Created
March 4, 2013 10:50
-
-
Save wereHamster/5081484 to your computer and use it in GitHub Desktop.
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
reduce :: [Int] -> [Int] | |
reduce (x:rest@(y:z)) = (x + y) : (reduce rest) | |
reduce _ = [] | |
pascal :: Int -> [Int] | |
pascal 1 = [1] | |
pascal 2 = [1,1] | |
pascal x = [1] ++ reduce (pascal (x - 1)) ++ [1] | |
center :: Int -> String -> String | |
center width string = | |
let padding = floor (fromIntegral (width - (length string)) / 2) | |
in (take padding $ repeat ' ') ++ string | |
main = do | |
putStrLn "" | |
putStrLn $ center 40 $ show $ pascal 1 | |
putStrLn $ center 40 $ show $ pascal 2 | |
putStrLn $ center 40 $ show $ pascal 3 | |
putStrLn $ center 40 $ show $ pascal 4 | |
putStrLn $ center 40 $ show $ pascal 5 | |
putStrLn $ center 40 $ show $ pascal 6 | |
putStrLn $ center 40 $ show $ pascal 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment