Project Euler

Problem #53

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, ^(5)C_(3) = 10.

In general,

^(n)C_(r) =
n!

r!(n−r)!
,where r ≤ n, n! = n×(n−1)×...×3×2×1, and 0! = 1.

It is not until n = 23, that a value exceeds one-million: ^(23)C_(10) = 1144066.

How many, not necessarily distinct, values of  ^(n)C_(r), for 1 ≤ n ≤ 100, are greater than one-million?

Erlang: Running time = 0.19s
+%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.

Ruby: Running time = 0.25s
+#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