Anonymous user
Arithmetic/Rational: Difference between revisions
no edit summary
Drkameleon (talk | contribs) (Added Arturo implementation) |
No edit summary |
||
Line 3,871:
</pre>
<small>Note that power(2,19) took over 270s under mpfr.js, so reduced to power(2,13) on that platform, making it finish in 0.99s</small>
=={{header|Picat}}==
<lang Picat>
</lang>main =>
foreach (I in 2..2**19, is_perfect(I))
println(I)
end.
is_perfect(N) => sum_rationals([$frac(1,D) : D in divisors(N)]) == $frac(2,1).
divisors(N) = [I : I in 1..N, N mod I == 0].
% only addition is needed
add(frac(A,B), frac(C,D)) = new_fract(A*D+B*C, B*D).
new_fract(A,B) = $frac(Num, Den) =>
G = gcd(A,B),
Num = A // G,
Den = B // G.
sum_rationals([X]) = X.
sum_rationals([X,Y|T]) = sum_rationals([add(X,Y)|T]).
{{out}}
<pre>
6
28
496
8128
</pre>
=={{header|PicoLisp}}==
|