5 $log = Logger
.new(STDERR)
6 $log.level
= Logger
::WARN
8 def amicable_pairs(limit
)
11 cache
<< n
.sum_of_proper_divisors
12 $log.debug
{ "Sum of proper divisors of #{n} is #{n.sum_of_proper_divisors}" }
16 if cache
[cache
[n
]] == n
and cache
[n
] > n
17 amicable_pairs
<< [n
, cache
[n
]]
18 $log.info
{ "Found amicable pairs #{n} and #{cache[n]}" }
24 def sum_of_amicable_pairs(limit
)
25 amicable_pairs(limit
).reduce(0) {|a
, p
| a
+= p
.reduce(:+)}
29 puts sum_of_amicable_pairs
10000