Created
January 24, 2013 07:57
-
-
Save wereHamster/4618553 to your computer and use it in GitHub Desktop.
primitive pascal triangle code 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
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] | |
main = do | |
putStrLn $ show $ pascal 1 | |
putStrLn $ show $ pascal 2 | |
putStrLn $ show $ pascal 3 | |
putStrLn $ show $ pascal 4 | |
putStrLn $ show $ pascal 5 | |
putStrLn $ show $ pascal 6 | |
putStrLn $ show $ pascal 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment