Skip to content

Instantly share code, notes, and snippets.

@jamesthompson
Created August 30, 2016 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesthompson/52913d2cf9d7d5d0d3ed0ca4f4c5f73f to your computer and use it in GitHub Desktop.
Save jamesthompson/52913d2cf9d7d5d0d3ed0ca4f4c5f73f to your computer and use it in GitHub Desktop.
Triangle string with alternating 0 and 1 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