Problem 15 (written in Ruby)
(21..40).to_a.inject(1){|r,s| r*=s } / (1..20).to_a.inject(1){|r,s| r*=s }
Problem:
http://odz.sakura.ne.jp/projecteuler/index.php?Problem%2015
単純に40C20だった。
brute-forceバージョン笑↓
X_MAX = 20
Y_MAX = 20$count = 0
def search(x, y)
if x == X_MAX and y == Y_MAX then
$count += 1
puts "counting #{$count}...." if $count % 100000 == 0
return
endsearch(x+1, y) if x < X_MAX
search(x, y+1) if y < Y_MAX
endsearch(0, 0)
puts "Answer = #{$count}"