binom :: Integer -> Integer -> Integer binom n k | k < 0 || k > n = 0 | 2*k > n = binom n (n-k) | k == 0 = 1 | otherwise = binom n (k-1) * (n-k+1) `div` k catalan :: [Integer] catalan = 1 : cathelp 1 1 where cathelp n last = next : cathelp (n+1) next where next = (2*n)*(2*n-1) * last `div` ((n+1)*n) partition :: [Integer] partition = 1 : [ partition_of k | k <- [1..] ] where partition_of k = sum [ sign * (partition !! (k-off)) | (sign, off) <- takeWhile ((<= k) . snd) pentagonal_offsets] pentagonal_offsets = zip (cycle [1,1,-1,-1]) $ concatMap (\n -> [(3*n-1)*n `div` 2, (3*n+1)*n `div` 2]) [1..]