Created
December 29, 2014 17:50
-
-
Save orionll/612bfdf0a71d1e2feb11 to your computer and use it in GitHub Desktop.
Christmas tree in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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