1 ! Copyright (c) 2008 Aaron Schaefer.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.combinatorics ranges sequences
7 ! https://projecteuler.net/problem=53
12 ! There are exactly ten ways of selecting three from five,
15 ! 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
17 ! In combinatorics, we use the notation, 5C3 = 10.
20 ! nCr = n! / r! * (n - r)!
21 ! where r ≤ n, n! = n * (n − 1) * ... * 3 * 2 * 1, and 0! = 1.
23 ! It is not until n = 23, that a value exceeds one-million:
26 ! How many values of nCr, for 1 ≤ n ≤ 100, are greater than
33 : euler053 ( -- answer )
34 23 100 [a..b] [ dup <iota> [ nCk 1000000 > ] with count ] map-sum ;
36 ! [ euler053 ] 100 ave-time
37 ! 52 ms ave run time - 4.44 SD (100 trials)