module ThueMorse where tms1 :: [Int] tms1 = buildtms1 [0] 1 where buildtms1 x n |(n `rem` 2 == 0) = buildtms1 (x++[(x !! (n `div` 2))]) (n+1) |(n `rem` 2 == 1) = buildtms1 (x++[1- (x !! ((n-1) `div` 2))]) (n+1) custinv [] = [] custinv x = (1-head x):(custinv (tail x)) tms3 :: [Int] tms3 = buildtms3 [0] 1 where buildtms3 x n = buildtms3 (x++(custinv x)) (n*2) intToBinary :: Int -> [Bool] intToBinary n | (n==0) = [] | (n `rem` 2 ==0) = intToBinary (n `div` 2) ++ [False] | (n `rem` 2 ==1) = intToBinary (n `div` 2) ++ [True] amountTrue :: [Bool] -> Int amountTrue [] = 0 amountTrue (x:xs) | (x==True) = 1+amountTrue(xs) | (x==False) = amountTrue(xs) tms4 :: [Int] tms4= buildtms4 0 where buildtms4 n |(amountTrue (intToBinary n) `rem` 2 ==0) = 0:(buildtms4 (n+1)) |(amountTrue (intToBinary n) `rem` 2 ==1) = 1:(buildtms4 (n+1))