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

no edit summary
(Add Factor)
No edit summary
 
(6 intermediate revisions by 6 users not shown)
Line 132:
4 9 16 25 36 36 49 81 121 144 169
</pre>
 
=={{header|BQN}}==
<syntaxhighlight lang="Quackerybqn">lists [3,4,34,25,9,12,36,56,36]
[2,8,81,169,34,55,76,49,7]
[75,121,75,144,35,16,46,35]⟩
Task ← ∧∘∾ ⌊⌾√⊸=⊸/¨
 
Task lists</syntaxhighlight>
{{out}}
<pre>⟨ 4 9 16 25 36 36 49 81 121 144 169 ⟩</pre>
 
=={{header|Delphi}}==
Line 186 ⟶ 196:
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight>
lists[][] = [ [ 3 4 34 25 9 12 36 56 36 ] [ 2 8 81 169 34 55 76 49 7 ] [ 75 121 75 144 35 16 46 35 ] ]
#
proc sort . d[] .
for i = 1 to len d[] - 1
for j = i + 1 to len d[]
if d[j] < d[i]
swap d[j] d[i]
.
.
.
.
func issqr x .
return if pow floor sqrt x 2 = x
.
for i to len lists[][]
for e in lists[i][]
if issqr e = 1
sqrs[] &= e
.
.
.
sort sqrs[]
print sqrs[]
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 198 ⟶ 235:
 
=={{header|Factor}}==
{{works with|Factor |0.99}}
<syntaxhighlight lang="factor">
USING: prettyprint project-euler.common sequences sorting ;
Line 245 ⟶ 282:
next i</syntaxhighlight>
{{out}}<pre>4 9 16 25 36 36 49 81 121 144 169</pre>
 
 
=={{header|Go}}==
Line 448 ⟶ 486:
<pre>REXX-ooRexx_5.0.0(MT)_64-bit 6.05 8 Sep 2020
Ordered squares: 4 9 16 25 36 36 49 81 121 144 169</pre>
 
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<syntaxhighlight lang="pascal">
Program SortedSquares;
{$mode ObjFPC}{$H+}
 
Uses sysutils,fgl;
 
Type
tmap = specialize TFPGList<integer>;
 
Const List1: array Of integer = (3,4,34,25,9,12,36,56,36);
Const List2: array Of integer = (2,8,81,169,34,55,76,49,7);
Const List3: array Of integer = (75,121,75,144,35,16,46,35);
 
Var list : specialize TFPGList<integer>;
 
Procedure addtolist(arr : Array Of integer);
Var i : integer;
Begin
For i In arr Do
If ((frac(sqrt(i)) = 0) {check if a square, there will be no fraction}
And (list.indexof(i) = -1)) {make sure number isn't in list already}
Then list.add(i);
End;
 
Function CompareInt(Const Item1,Item2: Integer): Integer;
Begin
result := item1 - item2;
End;
 
Var i : integer;
Begin
list := specialize TFPGList<integer>.create;
addtolist(list1);
addtolist(list2);
addtolist(list3);
List.Sort(@CompareInt); {quick sort the list}
For i In list Do
write(i:4);
list.destroy;
End.
</syntaxhighlight>
{{out}}
<pre>
4 9 16 25 36 49 81 121 144 169
</pre>
 
=={{header|Perl}}==
Line 525 ⟶ 611:
=={{header|Quackery}}==
 
<code>sqrt+</code> is defined at [[Isqrt (integer square root) of X#Quackery]].
 
<syntaxhighlight lang="Quackery"> [ sqrt+ nip 0 = ] is issquare ( n --> b )
 
[]
<syntaxhighlight lang="Quackery"> []
' [ [ 3 4 34 25 9 12 36 56 36 ]
[ 2 8 81 169 34 55 76 49 7 ]
Line 739 ⟶ 827:
=={{header|Wren}}==
{{libheader|Wren-math}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
 
var lists = [
45

edits