Arithmetic/Rational: Difference between revisions
Content added Content deleted
(Updated D entry) |
|||
Line 2,363: | Line 2,363: | ||
<lang ruby>require 'rational' #Only needed in Ruby < 1.9 |
<lang ruby>require 'rational' #Only needed in Ruby < 1.9 |
||
for candidate in 2 .. 2**19 |
for candidate in 2 .. 2**19 |
||
sum = Rational(1, candidate) |
sum = Rational(1, candidate) |
||
for factor in 2 ... candidate**0.5 |
for factor in 2 ... candidate**0.5 |
||
Line 2,375: | Line 2,375: | ||
end |
end |
||
end</lang> |
end</lang> |
||
{{out}} |
|||
It might be implemented like this: |
|||
<pre> |
|||
Sum of recipr. factors of 6 = 1 exactly perfect! |
|||
[insert implementation here] |
|||
Sum of recipr. factors of 28 = 1 exactly perfect! |
|||
Sum of recipr. factors of 120 = 2 exactly |
|||
Sum of recipr. factors of 496 = 1 exactly perfect! |
|||
Sum of recipr. factors of 672 = 2 exactly |
|||
Sum of recipr. factors of 8128 = 1 exactly perfect! |
|||
Sum of recipr. factors of 30240 = 3 exactly |
|||
Sum of recipr. factors of 32760 = 3 exactly |
|||
Sum of recipr. factors of 523776 = 2 exactly |
|||
</pre> |
|||
=={{header|Scheme}}== |
=={{header|Scheme}}== |