Minimum primes: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (syntax highlighting fixup automation)
m (→‎{{header|Wren}}: Changed to Wren S/H)
(6 intermediate revisions by 5 users not shown)
Line 54:
[ 43 101 79 59 67 ]
</pre>
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">lists: [
[ 5 45 23 21 67]
[43 22 78 46 38]
[ 9 98 12 54 53]
]
 
print map 0..dec size first lists 'i ->
first select.first (max map lists 'l -> l\[i])..∞ => prime?</syntaxhighlight>
 
{{out}}
 
<pre>43 101 79 59 67</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
Line 92 ⟶ 107:
43 101 79 59 67
</pre>
 
 
=={{header|BASIC256}}==
Line 205 ⟶ 219:
{{out}}
Same as Ring.
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
 
function IsPrime(N: int64): boolean;
{Fast, optimised prime test}
var I,Stop: int64;
begin
if (N = 2) or (N=3) then Result:=true
else if (n <= 1) or ((n mod 2) = 0) or ((n mod 3) = 0) then Result:= false
else
begin
I:=5;
Stop:=Trunc(sqrt(N+0.0));
Result:=False;
while I<=Stop do
begin
if ((N mod I) = 0) or ((N mod (I + 2)) = 0) then exit;
Inc(I,6);
end;
Result:=True;
end;
end;
 
 
type TIntArray = array of integer;
 
type TNumList = array [0..2, 0..4] of integer;
 
const NumLists: TNumList = (
(5,45,23,21,67),
(43,22,78,46,38),
(9,98,12,98,53));
 
 
procedure GetColPrimes(NumList: TNumList; var ColPrimes: TIntArray);
{Get the Maxium value, find next prime and store result in array}
var X,Y,I,M: integer;
var Highest: integer;
begin
for X:=0 to High(NumLists[0]) do
begin
Highest:=0;
for Y:=0 to High(NumList) do
if NumLists[Y,X]>Highest then Highest:=NumList[Y,X];
SetLength(ColPrimes,Length(ColPrimes)+1);
ColPrimes[High(ColPrimes)]:=Highest;
end;
for I:=0 to High(ColPrimes) do
begin
M:=ColPrimes[I];
if (M mod 2)=0 then Inc(M);
while not IsPrime(M) do Inc(M,2);
ColPrimes[I]:=M;
end;
end;
 
 
 
procedure ShowColumnPrimes(Memo: TMemo);
{Show min value for columns in NumLists}
var ColPrimes: TIntArray;
var I: integer;
var S: string;
begin
GetColPrimes(NumLists,ColPrimes);
S:='[';
for I:=0 to High(ColPrimes) do
begin
if I<>0 then S:=S+' ';
S:=S+IntToStr(ColPrimes[I]);
end;
S:=S+']';
Memo.Lines.Add(S);
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
[43 101 79 101 67]
</pre>
 
 
 
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
Line 296 ⟶ 400:
[43 101 79 59 67]
</pre>
 
=={{header|J}}==
<syntaxhighlight lang="j"> ] numbers =. 3 5 $ 5 45 23 21 67 43 22 78 46 38 9 98 12 54 53
5 45 23 21 67
43 22 78 46 38
9 98 12 54 53
 
4 p: <: >./ numbers
43 101 79 59 67</syntaxhighlight>
 
=={{header|jq}}==
Line 425 ⟶ 538:
{43,101,79,59,67}
</pre>
 
=={{header|Quackery}}==
 
<code>transpose</code> is defined at [[Matrix transposition#Quackery]].
 
<code>isprime</code> is defined at [[Primality by trial division#Quackery]].
 
<syntaxhighlight lang="Quackery"> ' [ 5 45 23 21 67 ]
' [ 43 22 78 46 38 ]
' [ 9 98 12 54 53 ]
3 pack transpose
[] swap witheach
[ unpack max max 1 -
[ 1+ dup isprime until ]
join ]
echo
</syntaxhighlight>
 
{{out}}
 
<pre>[ 43 101 79 59 67 ]</pre>
 
=={{header|Raku}}==
Line 517 ⟶ 651:
</pre>
 
=={{header|RPL}}==
====By the letter====
{{works with|HP|49g}}
≪ {5 45 23 21 67} {43 22 78 46 38} {9 98 12 54 53} → numbers1 numbers2 numbers3
≪ numbers1 numbers2 numbers3 3 ≪ MAX MAX ≫ DOLIST
{ } → max primes
≪ 1 max SIZE '''FOR''' j
max j GET
'''IF''' DUP ISPRIME? NOT '''THEN''' NEXTPRIME '''END'''
'primes' SWAP STO+
'''NEXT''' primes
≫ ≫ ≫ '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: {43 101 79 59 67}
</pre>
====Idiomatic====
No need for local variables.
≪ {5 45 23 21 67} {43 22 78 46 38} {9 98 12 54 53}
3 ≪ MAX MAX ≫ DOLIST
≪ '''IF''' DUP ISPRIME? NOT '''THEN''' NEXTPRIME '''END''' ≫ MAP
≫ '<span style="color:blue">TASK</span>' STO
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require "prime"
Line 527 ⟶ 683:
<pre>[43, 101, 79, 59, 67]
</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var lists = [
Line 542 ⟶ 699:
=={{header|Wren}}==
{{libheader|Wren-math}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
 
var numbers1 = [ 5, 45, 23, 21, 67]
9,476

edits