Skip to content

Instantly share code, notes, and snippets.

@Abhiroop
Last active March 13, 2018 13:41
Show Gist options
  • Save Abhiroop/c225836a3b20c2df1c190b80128e39f4 to your computer and use it in GitHub Desktop.
Save Abhiroop/c225836a3b20c2df1c190b80128e39f4 to your computer and use it in GitHub Desktop.
pascalLevel :: [[Int]]
pascalLevel = [1] : map foo pascalLevel
foo :: [Int] -> [Int]
foo x = zipWith (+) ([0] ++ x) (x ++ [0])
-- take 5 pascalLevel
-- [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
-------------------------------------------------------
-- To satisfy the original API requirement
pascal :: a -> Maybe [[Int]]
pascal () = Just pascalLevel
pascal _ = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment