Skip to content

Instantly share code, notes, and snippets.

@mmitou
Created April 20, 2013 13:04
Show Gist options
  • Select an option

  • Save mmitou/5425915 to your computer and use it in GitHub Desktop.

Select an option

Save mmitou/5425915 to your computer and use it in GitHub Desktop.
makePyramid :: Int -> [String]
makePyramid h | h < 1 = []
| otherwise = [makeLine n | n <- numbers]
where
numbers = take h [x | x <- [1..], odd x]
l = last numbers
makeLine n = spaces ++ asters ++ spaces
where
numOfSpaces = (l - n) `div` 2
spaces = [' ' | _ <- [1 .. numOfSpaces]]
asters = ['*' | _ <- [1 .. n]]
printPyramid :: Int -> IO ()
printPyramid n = mapM_ putStrLn $ makePyramid n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment