← go back

ok here is one

pairSum :: Num a => [a] -> [a]
pairSum [] = []
pairSum [x] = []
pairSum (x:y:[]) = [x + y]
pairSum (x:y:xs) = x + y : pairSum (y:xs)

pascal :: Integer -> [Integer]
pascal 0 = [1]
pascal x = [1] ++ (pairSum $ pascal (x - 1)) ++ [1]

main = mapM (print . pascal) [0..20]
Jul 23, 2023, 6:36 AM
2 0 1

Comments