Done puzzle 34
[project-euler.git] / euler23.rb
1 load 'divisors.rb'
2
3 require 'logger'
4 $log = Logger.new(STDERR)
5 $log.level = Logger::WARN
6
7 abundant_numbers = (12..28124).select {|i| i.abundant?}
8
9 candidates = Array.new(28124) {|i| i}
10 candidates[0] = nil
11
12 abundant_numbers.each_index do |i|
13 j = abundant_numbers.length - 1
14 while j >= i
15 candidates[abundant_numbers[i] + abundant_numbers[j]] = nil
16 $log.info {"Eliminating #{abundant_numbers[i] + abundant_numbers[j]} as the sum of #{abundant_numbers[i]} and #{abundant_numbers[j]} (i=#{i}, j=#{j})" }
17 j -= 1
18 end
19 end
20
21 # p candidates.compact
22 p candidates.compact.reduce(:+)
23
24 $log.close