Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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