Arithmetic derivative: Difference between revisions

Added Easylang
(Add Scala implementation)
(Added Easylang)
 
(One intermediate revision by one other user not shown)
Line 313:
D(10^20) / 7 = 200000000000000000000
</pre>
 
=={{header|EasyLang}}==
{{trans|Lua}}
<syntaxhighlight>
func lagarias n .
if n < 0
return -lagarias -n
.
if n = 0 or n = 1
return 0
.
f = 2
while n mod f <> 0
f += 1
.
q = n / f
if q = 1
return 1
.
return q * lagarias f + f * lagarias q
.
for n = -99 to 100
write lagarias n & " "
.
</syntaxhighlight>
 
=={{header|Factor}}==
Line 1,632 ⟶ 1,657:
D(10^19) / 7 = 19000000000000000000
D(10^20) / 7 = 200000000000000000000
</pre>
 
=={{header|XPL0}}==
{{trans|ALGOL W}}
<syntaxhighlight lang "XPL0">function integer Lagarias (N); \Lagarias arithmetic derivative
integer N;
integer F, Q;
 
function integer SmallPF (J, K); \Smallest prime factor
integer J, K;
return if rem(J/K) = 0 then K else SmallPF(J, K+1);
 
begin
if N < 0
then return -Lagarias (-N)
else if N = 0 or N = 1
then return 0
else begin
F := SmallPF (N, 2); Q := N / F;
return if Q = 1
then 1
else Q * Lagarias (F) + F * Lagarias (Q)
end;
end \Lagarias\ ;
 
integer N;
begin
for N:= -99 to 100 do begin
IntOut(0, Lagarias(N) );
if rem(N/10) = 0 then CrLf(0) else ChOut(0, 9\tab\);
end;
end</syntaxhighlight>
{{out}}
<pre>
-75 -77 -1 -272 -24 -49 -34 -96 -20 -123
-1 -140 -32 -45 -22 -124 -1 -43 -108 -176
-1 -71 -18 -80 -55 -39 -1 -156 -1 -59
-26 -72 -1 -61 -18 -192 -51 -33 -1 -92
-1 -31 -22 -92 -16 -81 -1 -56 -20 -45
-14 -112 -1 -25 -39 -48 -1 -41 -1 -68
-16 -21 -1 -60 -12 -19 -14 -80 -1 -31
-1 -32 -27 -15 -10 -44 -1 -13 -10 -24
-1 -21 -1 -32 -8 -9 -1 -16 -1 -7
-6 -12 -1 -5 -1 -4 -1 -1 0 0
0 1 1 4 1 5 1 12 6 7
1 16 1 9 8 32 1 21 1 24
10 13 1 44 10 15 27 32 1 31
1 80 14 19 12 60 1 21 16 68
1 41 1 48 39 25 1 112 14 45
20 56 1 81 16 92 22 31 1 92
1 33 51 192 18 61 1 72 26 59
1 156 1 39 55 80 18 71 1 176
108 43 1 124 22 45 32 140 1 123
20 96 34 49 24 272 1 77 75 140
</pre>
1,983

edits