Skip to content

Instantly share code, notes, and snippets.

@orionll
Created December 29, 2014 17:50
Show Gist options
  • Save orionll/612bfdf0a71d1e2feb11 to your computer and use it in GitHub Desktop.
Save orionll/612bfdf0a71d1e2feb11 to your computer and use it in GitHub Desktop.
Christmas tree in Haskell
-- Usage:
-- runhaskell newyear.hs n
-- This will print a nice christmas tree. For n=5:
--
-- *
-- * *
-- * * *
-- * * * *
-- * * * * *
-- Happy New Year!
import Data.List
import System.Environment
spaces total n = take (total-n) (repeat ' ')
stars n = intersperse ' ' $ take n (repeat '*')
line total n = spaces total n ++ stars n
main = do [arg] <- getArgs
let total = read arg in mapM_ putStrLn (map (line total) [1..total])
putStrLn "Happy New Year!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment