Minimum primes: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|Phix}}: %V -> %v) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 19:
Can handle the possibility of the maximum elements being negative, 0, 1 or 2.
{{libheader|ALGOL 68-primes}}
<
PR read "primes.incl.a68" PR
[]INT numbers1 = ( 5, 45, 23, 21, 67 );
Line 49:
FOR i TO UPB prime list DO print( ( " ", whole( prime list[ i ], 0 ) ) ) OD;
print( ( " ]" ) )
END</
{{out}}
<pre>
Line 55:
</pre>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f MINIMUM_PRIMES.AWK
BEGIN {
Line 87:
}
function max(x,y) { return((x > y) ? x : y) }
</syntaxhighlight>
{{out}}
<pre>
Line 96:
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<
dim Num2 = {43,22,78,46,38}
dim Num3 = { 9,98,12,54,53}
Line 126:
end while
return True
end function</
=={{header|C}}==
{{trans|Wren}}
<
#define TRUE 1
Line 171:
printf("\n");
return 0;
}</
{{out}}
Line 181:
== {{header|C#|CSharp}} ==
{{trans|Ring}}...solution #1.
<
using System.Linq;
using static System.Console;
Line 202:
Nums[i] = nxtPrime(new int[]{ Num1[i], Num2[i], Num3[i] }.Max());
WriteLine("The minimum prime numbers of three lists = [{0}]", string.Join(",", Nums));
Write("done..."); } }</
{{out}}
Same as Ring.
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
<
// Minimum primes. Nigel Galloway: October 29th., 2021
let N1,N2,N3=[5;45;23;21;67],[43;22;78;46;38],[9;98;12;54;53]
let fN g=primes32()|>Seq.find((<=)g)
printfn "%A" (List.zip3 N1 N2 N3|>List.map(fun(n,g,l)->fN(max (max n g) l)))
</syntaxhighlight>
{{out}}
<pre>
Line 218:
</pre>
=={{header|Factor}}==
<
{ 5 45 23 21 67 } { 43 22 78 46 38 } { 9 98 12 54 53 }
[ max max 1 - next-prime ] 3map .</
{{out}}
<pre>
Line 229:
=={{header|FreeBASIC}}==
<
Function isPrime(Byval ValorEval As Integer) As Boolean
Line 257:
Next n
Print !"\b\b ]"
Sleep</
{{out}}
<pre>
Line 267:
{{trans|Wren}}
{{libheader|Go-rcu}}
<
import (
Line 290:
}
fmt.Println(primes)
}</
{{out}}
Line 304:
Two solutions are presented following these preliminaries:
<syntaxhighlight lang="jq">
include "is_prime"; # reminder
Line 315:
if m%2 == 0 then primes(m+1;n)
else range(m; n; 2) | select(is_prime)
end;</
'''Explicit Iteration'''
<
| [Numbers1[.], Numbers2[.], Numbers3[.]] | max
| first(primes(.; infinite))]</
'''Functional'''
<
| transpose
| [map(max | first(primes(.; infinite)))] </
{{out}}
<pre>
Line 330:
=={{header|Julia}}==
<
println(nextprime.(maximum(hcat([5,45,23,21,67], [43,22,78,46,38], [9,98,12,54,53]), dims=2)))
</
<pre>[43; 101; 79; 59; 67;;]</pre>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
If[PrimeQ@Max@x, Max@x, NextPrime@Max@x]
MapThread[
minPrime@{##} &, {{5., 45, 23, 21, 67}, {43, 22, 78, 46, 38}, {9, 98,
12, 54, 53}}]</
{{out}}<pre>
Line 348:
=={{header|Nim}}==
<
Numbers1 = [ 5, 45, 23, 21, 67]
Numbers2 = [43, 22, 78, 46, 38]
Line 379:
numbers[i] = minPrime(m)
echo numbers</
{{out}}
Line 386:
=={{header|Perl}}==
{{libheader|ntheory}}
<
use strict; # https://rosettacode.org/wiki/Minimum_primes
Line 401:
} 0 .. 4;
print "@Primes\n";</
{{out}}
<pre>
Line 408:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">nextprime</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
Line 420:
<span style="color: #0000FF;">{</span><span style="color: #000000;">43</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">22</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">78</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">46</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">38</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">98</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">12</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">54</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">53</span><span style="color: #0000FF;">}})})</span>
<!--</
{{out}}
<pre>
Line 429:
Seems kind of pointless to specify a maximum of 5 terms when there are only 5 elements in each list but... ¯\_(ツ)_/¯
<syntaxhighlight lang="raku"
sub next-prime { ($^m..*).first: &is-prime }</
{{out}}
<pre>(43 101 79 59 67)</pre>
Line 437:
=={{header|Ring}}==
===Solution #1===
<
Num1 = [ 5,45,23,21,67]
Line 463:
else j++ ok
if j * j > x exit ok
end return string(x)</
{{out}}
<pre>
Line 471:
</pre>
===Solution #2===
<
load "stdlib.ring"
see "working..." + nl
Line 509:
txt = txt + "]"
see txt
</syntaxhighlight>
{{out}}
<pre>
Line 518:
=={{header|Ruby}}==
<
numbers1 = [ 5, 45, 23, 21, 67]
numbers2 = [43, 22, 78, 46, 38]
numbers3 = [ 9, 98, 12, 54, 53]
p [numbers1, numbers2, numbers3].transpose.map{|ar| (ar.max..).find(&:prime?) }</
{{out}}
<pre>[43, 101, 79, 59, 67]
</pre>
=={{header|Sidef}}==
<
[ 5,45,23,21,67],
[43,22,78,46,38],
Line 534:
]
say lists.zip.map { next_prime(.max - 1) }</
{{out}}
<pre>
Line 542:
=={{header|Wren}}==
{{libheader|Wren-math}}
<
var numbers1 = [ 5, 45, 23, 21, 67]
Line 554:
primes[n] = max
}
System.print(primes)</
{{out}}
Line 562:
=={{header|XPL0}}==
<
int N, I;
[if N <= 1 then return false;
Line 581:
IntOut(0, Max); ChOut(0, ^ );
];
]</
{{out}}
|