DEV Community


Discussion on: Daily Challenge #203 - Pascal's Triangle

craigmc08 profile image
Craig McIlwrath


factorial :: (Integral a) => a -> a
factorial n = product [1..n]

choose :: (Integral a, Num b) => a -> a -> b
n `choose` k = fromIntegral $ factorial n `div` (factorial k * factorial (n - k)) 

easyLine :: (Integral a, Num b) => a -> b
easyLine n = (2 * n) `choose` n

From Wikipedia

The sum of the squares of the elements of row n equals the middle element of row 2n...In general form:

k=0n(nk)2=(2nn) \sum_{k = 0}^{n} {n \choose k}^2 = {2n \choose n}

p.s. I got to use the new latex feature for that!