Created
August 30, 2016 12:42
-
-
Save jamesthompson/52913d2cf9d7d5d0d3ed0ca4f4c5f73f to your computer and use it in GitHub Desktop.
Triangle string with alternating 0 and 1 characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (intersperse) | |
import Data.Monoid (mconcat) | |
triangleIO :: IO () | |
triangleIO = putStrLn triangle | |
triangle :: String | |
triangle = mconcat . intersperse "\n" . fmap (intersperse ' ') $ cycle ['0'] | |
where cycle x = x : (cycle x >>= growOne) | |
growOne (x:z) = [opp x:x:z] | |
opp '0' = '1' | |
opp '1' = '0' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment