Add all the A tasks
This commit is contained in:
parent
2dd7375f96
commit
051504d65b
1608 changed files with 18584 additions and 0 deletions
14
Task/Arithmetic-Rational/Ruby/arithmetic-rational.rb
Normal file
14
Task/Arithmetic-Rational/Ruby/arithmetic-rational.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
require 'rational' #Only needed in Ruby < 1.9
|
||||
|
||||
for candidate in 2 .. 2**19:
|
||||
sum = Rational(1, candidate)
|
||||
for factor in 2 ... candidate**0.5
|
||||
if candidate % factor == 0
|
||||
sum += Rational(1, factor) + Rational(1, candidate / factor)
|
||||
end
|
||||
end
|
||||
if sum.denominator == 1
|
||||
puts "Sum of recipr. factors of %d = %d exactly %s" %
|
||||
[candidate, sum.to_i, sum == 1 ? "perfect!" : ""]
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue