Skip to content

Instantly share code, notes, and snippets.

@kenprice
Created January 1, 2019 23:23
Show Gist options
  • Save kenprice/ad8e2c964ec58300623697fd0cefa107 to your computer and use it in GitHub Desktop.
Save kenprice/ad8e2c964ec58300623697fd0cefa107 to your computer and use it in GitHub Desktop.
Project Euler Problem 15
pascal :: Int -> [Int]
pascal k = iterate pascal' [] !! k
pascal' :: [Int] -> [Int]
pascal' [] = [1]
pascal' xs = [1] ++ zipWith (+) xs (tail xs) ++ [1]
getNumLatticePathsForGrid :: Int -> Int
getNumLatticePathsForGrid n = pascal (n * 2 + 1) !! n
main :: IO()
main = putStrLn (show (getNumLatticePathsForGrid 20))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment