Project Euler – Problem 53 Solution


There are exactly ten ways of selecting three from five, 12345:

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

In combinatorics, we use the notation, 5C3 = 10.

In general,


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

How many, not necessarily distinct, values of  nCr, for 1 <= n <= 100, are greater than one-million?


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 =
    |> List.collect (fun n -> [1I..n] |> (fun r -> C n r))
    |> List.filter (fun x -> x > 1000000I)
    |> List.length

Yan Cui

I’m an AWS Serverless Hero and the author of Production-Ready Serverless. I have run production workload at scale in AWS for nearly 10 years and I have been an architect or principal engineer with a variety of industries ranging from banking, e-commerce, sports streaming to mobile gaming. I currently work as an independent consultant focused on AWS and serverless.

You can contact me via Email, Twitter and LinkedIn.

Hire me.