grays = iterate (\gs ->map (False:) gs ++ map (True:) (reverse gs)) [[]] main = do mapM (\n -> do mapM_ print . (grays !!) $ n putStrLn "") [0..4] print $ grays !! 3