Combinatorics in Haskell
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 lines
358 B

module Matchings where
import Data.MemoTrie
import Binomial
-- number of ways to match up k elements with n elements
-- matchings may be partial
matchings :: Int -> Int -> Integer
matchings = memo2 m where
m n k = if n > k
then matchings k n
else sum [ binomial n i * product [fromIntegral (k-i+1) .. fromIntegral k] | i <- [0 .. n]]