Jump to content

Minimum primes: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Phix}}: %V -> %v)
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}}
<langsyntaxhighlight lang="algol68">BEGIN # show the minimum prime >= the maximum elements of three lists #
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</langsyntaxhighlight>
{{out}}
<pre>
Line 55:
</pre>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f MINIMUM_PRIMES.AWK
BEGIN {
Line 87:
}
function max(x,y) { return((x > y) ? x : y) }
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 96:
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight BASIC256lang="basic256">dim Num1 = { 5,45,23,21,67}
dim Num2 = {43,22,78,46,38}
dim Num3 = { 9,98,12,54,53}
Line 126:
end while
return True
end function</langsyntaxhighlight>
 
 
=={{header|C}}==
{{trans|Wren}}
<langsyntaxhighlight lang="c">#include <stdio.h>
 
#define TRUE 1
Line 171:
printf("\n");
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 181:
== {{header|C#|CSharp}} ==
{{trans|Ring}}...solution #1.
<langsyntaxhighlight lang="csharp">using System;
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..."); } }</langsyntaxhighlight>
{{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#)]
<langsyntaxhighlight lang="fsharp">
// 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>
</lang>
{{out}}
<pre>
Line 218:
</pre>
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: math math.order math.primes prettyprint sequences ;
 
{ 5 45 23 21 67 } { 43 22 78 46 38 } { 9 98 12 54 53 }
[ max max 1 - next-prime ] 3map .</langsyntaxhighlight>
{{out}}
<pre>
Line 229:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">#define MAX(a, b) iif((a) > (b), (a), (b))
 
Function isPrime(Byval ValorEval As Integer) As Boolean
Line 257:
Next n
Print !"\b\b ]"
Sleep</langsyntaxhighlight>
{{out}}
<pre>
Line 267:
{{trans|Wren}}
{{libheader|Go-rcu}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 290:
}
fmt.Println(primes)
}</langsyntaxhighlight>
 
{{out}}
Line 304:
 
Two solutions are presented following these preliminaries:
<syntaxhighlight lang="jq">
<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;</langsyntaxhighlight>
'''Explicit Iteration'''
<langsyntaxhighlight lang="jq">[range(0;5)
| [Numbers1[.], Numbers2[.], Numbers3[.]] | max
| first(primes(.; infinite))]</langsyntaxhighlight>
'''Functional'''
<langsyntaxhighlight lang="jq">[Numbers1, Numbers2, Numbers3]
| transpose
| [map(max | first(primes(.; infinite)))] </langsyntaxhighlight>
{{out}}
<pre>
Line 330:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Primes
 
println(nextprime.(maximum(hcat([5,45,23,21,67], [43,22,78,46,38], [9,98,12,54,53]), dims=2)))
</langsyntaxhighlight>{{out}}
<pre>[43; 101; 79; 59; 67;;]</pre>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">minPrime[x_List] :=
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}}]</langsyntaxhighlight>
 
{{out}}<pre>
Line 348:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">const
Numbers1 = [ 5, 45, 23, 21, 67]
Numbers2 = [43, 22, 78, 46, 38]
Line 379:
numbers[i] = minPrime(m)
 
echo numbers</langsyntaxhighlight>
 
{{out}}
Line 386:
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Minimum_primes
Line 401:
} 0 .. 4;
 
print "@Primes\n";</langsyntaxhighlight>
{{out}}
<pre>
Line 408:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
<!--</langsyntaxhighlight>-->
{{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" perl6line>say ([Zmax] <5 45 23 21 67>, <43 22 78 46 38>, <9 98 12 54 53>)».&next-prime[^5];
 
sub next-prime { ($^m..*).first: &is-prime }</langsyntaxhighlight>
{{out}}
<pre>(43 101 79 59 67)</pre>
Line 437:
=={{header|Ring}}==
===Solution #1===
<langsyntaxhighlight lang="ring">? "working..."
 
Num1 = [ 5,45,23,21,67]
Line 463:
else j++ ok
if j * j > x exit ok
end return string(x)</langsyntaxhighlight>
{{out}}
<pre>
Line 471:
</pre>
===Solution #2===
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
see "working..." + nl
Line 509:
txt = txt + "]"
see txt
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 518:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require "prime"
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?) }</langsyntaxhighlight>
{{out}}
<pre>[43, 101, 79, 59, 67]
</pre>
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var lists = [
[ 5,45,23,21,67],
[43,22,78,46,38],
Line 534:
]
 
say lists.zip.map { next_prime(.max - 1) }</langsyntaxhighlight>
{{out}}
<pre>
Line 542:
=={{header|Wren}}==
{{libheader|Wren-math}}
<langsyntaxhighlight lang="ecmascript">import "./math" for Int
 
var numbers1 = [ 5, 45, 23, 21, 67]
Line 554:
primes[n] = max
}
System.print(primes)</langsyntaxhighlight>
 
{{out}}
Line 562:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func IsPrime(N); \Return 'true' if N is a prime number
int N, I;
[if N <= 1 then return false;
Line 581:
IntOut(0, Max); ChOut(0, ^ );
];
]</langsyntaxhighlight>
 
{{out}}
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.