Skip to content

Instantly share code, notes, and snippets.

@wereHamster
Created January 24, 2013 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wereHamster/4618553 to your computer and use it in GitHub Desktop.
Save wereHamster/4618553 to your computer and use it in GitHub Desktop.
primitive pascal triangle code in haskell
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