Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {- Print the first n elements of the Thue-Morse sequence. The Thue-Morse sequence
- is a binary sequence (it comprises of only 1's and 0's) beginning with 0, which
- is derived by repeatedly appending an inverted version of the sequence to the
- sequence itself. The first few iterations look like this:
- 0
- 01
- 0110
- 01101001
- 0110100110010110
- etc. -}
- main = interact $ concatMap show . flip take tmSequence . read
- tmSequence = concat helper where
- helper = [0] : map (concatMap invert . flip take helper) [1..]
- invert = map (1 -)
- -- Golfed (86 bytes)
- main=interact$c.map show.(`take`c t).read
- t=[0]:map(map(1-).c.(`take`t))[1..]
- c=concat
- -- Fibonacci
- fib = 0 : 1 : zipWith (+) fib (tail fib)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement