Collect and sort square numbers in ascending order from three lists: Difference between revisions

Added XPL0 example.
m (→‎{{header|ooRexx}}: show duplicates)
(Added XPL0 example.)
Line 437:
<pre>
[4, 9, 16, 25, 36, 36, 49, 81, 121, 144, 169]
</pre>
 
=={{header|XPL0}}==
The task description seems to dictate how a program is supposed to solve
this, rather than merely provide a procedure that determines the
solution. XPL0 doesn't have a built-in list capability like Python. A
simple substitute is to treat the lists as arrays. A complication is that
list[3] is shorter than the others, which is adjusted here. XPL0 also doesn't
have a built-in sort routine (although one is provided in its library).
Displaying a small number of sorted items is easily done with a few lines
of code.
<lang XPL0>int List(3+1), Min, I, J, S, MI, MJ;
def Inf = -1>>1;
[List(1):= [3,4,34,25,9,12,36,56,36];
List(2):= [2,8,81,169,34,55,76,49,7];
List(3):= [75,121,75,144,35,16,46,35,Inf];
loop [Min:= Inf;
for I:= 1 to 3 do
for J:= 0 to 8 do
[S:= sqrt(List(I,J));
if S*S = List(I,J) then
if List(I,J) <= Min then
[Min:= List(I,J); MI:= I; MJ:= J];
];
if Min = Inf then quit;
IntOut(0, Min); ChOut(0, ^ );
List(MI, MJ):= Inf;
];
]</lang>
 
{{out}}
<pre>
4 9 16 25 36 36 49 81 121 144 169
</pre>
772

edits