Amicable pairs: Difference between revisions

Add Draco
(Added Forth entry)
(Add Draco)
Line 1,428:
=={{header|Delphi}}==
See [https://rosettacode.org/wiki/Amicable_pairs#Pascal Pascal].
 
=={{header|Draco}}==
<lang draco>/* Fill a given array such that for each N,
* P[n] is the sum of proper divisors of N */
proc nonrec propdivs([*] word p) void:
word i, j, max;
max := dim(p,1)-1;
for i from 0 upto max do p[i] := 0 od;
for i from 1 upto max/2 do
for j from i*2 by i upto max do
p[j] := p[j] + i
od
od
corp
 
/* Find all amicable pairs between 0 and 20,000 */
proc nonrec main() void:
word MAX = 20000;
word i, j;
[MAX] word p;
propdivs(p);
for i from 1 upto MAX-1 do
for j from i+1 upto MAX-1 do
if p[i]=j and p[j]=i then
writeln(i:5, ", ", j:5)
fi
od
od
corp</lang>
{{out}}
<pre> 220, 284
1184, 1210
2620, 2924
5020, 5564
6232, 6368
10744, 10856
12285, 14595
17296, 18416</pre>
 
=={{header|EchoLisp}}==
2,125

edits