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,
nCr = | n! r!(nr)! |
,where r n, n! = n(n1)...321, and 0! = 1. |
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?
%run_procs %choose %product p53()-> Ans=run_procs(100,fun(I)->[euler,p53,[I,1,0,self()]] end, fun(A,{done,B})->A+B end,0), io:format("~w~n",[Ans]). p53(N,N,Total,Parent)->Parent!{done,Total}; p53(N,R,Total,Parent)-> C=choose(N,R), if C>1000000->p53(N,R+1,Total+1,Parent); true->p53(N,R+1,Total,Parent) end.
#choose #factorial def p53 res=0 (1..100).each do |n| (1...n).each do |r| res+=1 if choose(n,r)>1000000 end end puts res end