Collect and sort square numbers in ascending order from three lists: Difference between revisions
Collect and sort square numbers in ascending order from three lists (view source)
Revision as of 20:00, 26 August 2022
, 1 year agosyntax highlighting fixup automation
Alpha bravo (talk | contribs) (Added AutoHotkey) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 9:
=={{header|11l}}==
<
[Int] squares
Line 21:
squares.sort()
print(squares)</
{{out}}
Line 30:
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-rows}}
<
# lists are represented by arrays in this sample #
PR read "rows.incl.a68" PR # sorting and printing utilities #
Line 62:
QUICKSORT squares FROMELEMENT 1 TOELEMENT r pos;
SHOW squares[ 1 : r pos ]
END</
{{out}}
<pre>
Line 69:
=={{header|Arturo}}==
<
[3,4,34,25,9,12,36,56,36]
[2,8,81,169,34,55,76,49,7]
Line 78:
square?: function [n]-> contains? squares n
print select sort fold.seed:[] lists [a,b][a++b] => square?</
{{out}}
Line 85:
=={{header|AutoHotkey}}==
<
list[1] := [3,4,34,25,9,12,36,56,36]
Line 98:
for n, obj in t
for i, v in obj
result.push(n)</
{{out}}
<pre>[4, 9, 16, 25, 36, 36, 49, 81, 121, 144, 169]</pre>
=={{header|AWK}}==
<
# syntax: GAWK -f COLLECT_AND_SORT_SQUARE_NUMBERS_IN_ASCENDING_ORDER_FROM_THREE_LISTS.AWK
BEGIN {
Line 127:
return (int(sqrt(n))^2 == n)
}
</syntaxhighlight>
{{out}}
<pre>
Line 134:
=={{header|F_Sharp|F#}}==
<
// Collect and sort square numbers in ascending order from three lists. Nigel Galloway: December 21st., 2021
let fN g=g*g in printfn "%A" (([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])|>List.filter(fun n->(float>>sqrt>>int>>fN)n=n)|>List.sort)
</syntaxhighlight>
{{out}}
<pre>
Line 143:
</pre>
=={{header|FreeBASIC}}==
<
if int(sqr(n))^2=n then return true else return false
end function
Line 173:
for i = 0 to ubound(squares) 'output data
print squares(i);" ";
next i</
{{out}}<pre>4 9 16 25 36 36 49 81 121 144 169</pre>
=={{header|Go}}==
<
import (
Line 206:
sort.Ints(squares)
fmt.Println(squares)
}</
{{out}}
Line 217:
'''Works with gojq, the Go implementation of jq'''
<
'''The Task'''
<syntaxhighlight lang="text">def lists: [
[3,4,34,25,9,12,36,56,36],
[2,8,81,169,34,55,76,49,7],
Line 226:
];
[lists[][]] | unique | map(select(isSquare))</
{{out}}
<pre>
Line 234:
=={{header|Julia}}==
vcat is list "addition" in Julia.
<
[3,4,34,25,9,12,36,56,36],
[2,8,81,169,34,55,76,49,7],
Line 243:
sort!(squares)
println(squares)
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
list2 = {2, 8, 81, 169, 34, 55, 76, 49, 7};
list3 = {75, 121, 75, 144, 35, 16, 46, 35};
Sort@Select[Join[list1, list2, list3], IntegerQ[Sqrt[#]] &]</
{{out}}<pre>
Line 255:
=={{header|ooRexx}}==
<
Say v
l.1=.array~of(3,4,34,25,9,12,36,56,36)
Line 303:
End
Say ol
Exit</
{{out}}
<pre>REXX-ooRexx_5.0.0(MT)_64-bit 6.05 8 Sep 2020
Line 310:
=={{header|Perl}}==
{{libheader|ntheory}}
<
use strict; # https://rosettacode.org/wiki/Add_and_sort_square_numbers_in_ascending_order_from_three_lists
Line 323:
my $sum = sum my @squares = grep is_square($_), sort { $a <=> $b } map @$_, @lists;
print "sum $sum - @squares\n";</
{{out}}
<pre>
Line 330:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">squares</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">lists</span><span style="color: #0000FF;">)</span>
Line 342:
<span style="color: #0000FF;">{</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span><span style="color: #000000;">81</span><span style="color: #0000FF;">,</span><span style="color: #000000;">169</span><span style="color: #0000FF;">,</span><span style="color: #000000;">34</span><span style="color: #0000FF;">,</span><span style="color: #000000;">55</span><span style="color: #0000FF;">,</span><span style="color: #000000;">76</span><span style="color: #0000FF;">,</span><span style="color: #000000;">49</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">75</span><span style="color: #0000FF;">,</span><span style="color: #000000;">121</span><span style="color: #0000FF;">,</span><span style="color: #000000;">75</span><span style="color: #0000FF;">,</span><span style="color: #000000;">144</span><span style="color: #0000FF;">,</span><span style="color: #000000;">35</span><span style="color: #0000FF;">,</span><span style="color: #000000;">16</span><span style="color: #0000FF;">,</span><span style="color: #000000;">46</span><span style="color: #0000FF;">,</span><span style="color: #000000;">35</span><span style="color: #0000FF;">}})</span>
<!--</
Alternatively, and a smidgen faster but not enough to be measurable here, you could replace that inner while loop with:
<!--<
<span style="color: #004080;">integer</span> <span style="color: #000000;">m</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">[$],</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">d</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">m</span><span style="color: #0000FF;">></span><span style="color: #000000;">s</span> <span style="color: #008080;">do</span> <span style="color: #000000;">d</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">;</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">;</span> <span style="color: #000000;">sq</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">;</span> <span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</
{{out}}
<pre>
Line 355:
=={{header|Python}}==
<
import math
Line 374:
print(Squares)
print("done...")
</syntaxhighlight>
{{out}}
<pre>
Line 383:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
[3,4,34,25,9,12,36,56,36],
Line 392:
put 'Added - Sorted';
put ' ' ~ $s.sum ~ ' ' ~ $s.gist;</
<pre>Added - Sorted
690 (4 9 16 25 36 36 49 81 121 144 169)
Line 398:
=={{header|REXX}}==
<
Say v
l.=0
Line 452:
End
Say ol
Exit</
{{out}}
<pre>REXX-Regina_3.9.4(MT) 5.00 25 Oct 2021
Line 459:
=={{header|Ring}}==
<
load "stdlib.ring"
Line 499:
txt = txt + "]"
see txt
</syntaxhighlight>
{{out}}
<pre>
Line 508:
=={{header|Sidef}}==
<
[3,4,34,25,9,12,36,56,36],
[2,8,81,169,34,55,76,49,7],
Line 514:
]
say lists.flat.grep{.is_square}.sort</
{{out}}
Line 523:
=={{header|Wren}}==
{{libheader|Wren-math}}
<
var lists = [
Line 536:
}
squares.sort()
System.print(squares)</
{{out}}
Line 552:
Displaying a small number of sorted items is easily done with a few lines
of code.
<
def Inf = -1>>1;
[List(1):= [3,4,34,25,9,12,36,56,36];
Line 569:
List(MI, MJ):= Inf;
];
]</
{{out}}
|