Ad
Code
Diff
  • module NCR where
    
    --Combinations nCr
    comb:: Integer -> Integer -> Integer
    comb n r = factorial n `div` (factorial r * factorial (n-r))
      where
      factorial n = foldr (*) 1 [2..n]
    • module NCR where
    • --Combinations nCr
    • comb:: Integer -> Integer -> Integer
    • comb n r | n/=r = (factorial n) `div` (factorial r * factorial (n-r) )
    • | n==r = (factorial n) `div` (factorial r)
    • factorial n= foldl (*) 1 [1..n]
    • comb n r = factorial n `div` (factorial r * factorial (n-r))
    • where
    • factorial n = foldr (*) 1 [2..n]