Prob­lem

There are exactly ten ways of select­ing three from five, 12345:

123, 124, 125, 134, 135, 145, 234, 235, 245, and 345

In com­bi­na­torics, we use the nota­tion, 5C3 = 10.

In gen­eral,

image

It is not until n = 23, that a value exceeds one-million: 23C10 = 1144066.

How many, not nec­es­sar­ily dis­tinct, val­ues of  nCr, for 1 <= n <= 100, are greater than one-million?

Solu­tion

let factorial n = if (n = 0I) then 1I else [1I..n] |> List.reduce (*)

let C n r = if r <= n then (factorial n) / ((factorial r) * (factorial (n - r))) else 0I

let answer =
    [1I..100I]
    |> List.collect (fun n -> [1I..n] |> List.map (fun r -> C n r))
    |> List.filter (fun x -> x > 1000000I)
    |> List.length
Share

Leave a Reply