Ad

This one should be faster since we only compute 2 products of less numbers.

Code
Diff
  • module NCR where
    
    --Combinations nCr
    comb:: Integer -> Integer -> Integer
    comb n r = product [n-r+1..n] `div` product [2..r]
    • module NCR where
    • --Combinations nCr
    • comb:: Integer -> Integer -> Integer
    • comb n r = factorial n `div` (factorial r * factorial (n-r))
    • where
    • factorial n = product [1 .. n]
    • comb n r = product [n-r+1..n] `div` product [2..r]