Arithmetic/Rational: Difference between revisions
→{{header|Ruby}}: Speed up by using Integer.sqrt
(added Ol) |
(→{{header|Ruby}}: Speed up by using Integer.sqrt) |
||
Line 3,809:
=={{header|Ruby}}==
Ruby has a Rational class in it's core since 1.9.
<lang ruby>
for candidate in 2 .. 2**19
sum = Rational(1, candidate)
for factor in 2 .. Integer.
if candidate % factor == 0
sum += Rational(1, factor) + Rational(1, candidate / factor)
|