Triplet of three numbers: Difference between revisions
Content added Content deleted
No edit summary |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 8: | Line 8: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">V n = 6000 |
||
V p = [0B] * 6000 |
V p = [0B] * 6000 |
||
Line 20: | Line 20: | ||
L.continue |
L.continue |
||
E |
E |
||
print(f:‘{i:4}: {i - 1:4} {i + 3:4} {i + 5:4}’)</ |
print(f:‘{i:4}: {i - 1:4} {i + 3:4} {i + 5:4}’)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 74: | Line 74: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
{{libheader|Action! Sieve of Eratosthenes}} |
{{libheader|Action! Sieve of Eratosthenes}} |
||
< |
<syntaxhighlight lang="action!">INCLUDE "H6:SIEVE.ACT" |
||
PROC Main() |
PROC Main() |
||
Line 91: | Line 91: | ||
OD |
OD |
||
PrintF("%E%EThere are %I triplets",count) |
PrintF("%E%EThere are %I triplets",count) |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Triplet_of_three_numbers.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Triplet_of_three_numbers.png Screenshot from Atari 8-bit computer] |
||
Line 107: | Line 107: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_Io; |
||
procedure Triplets is |
procedure Triplets is |
||
Line 151: | Line 151: | ||
end if; |
end if; |
||
end loop; |
end loop; |
||
end Triplets;</ |
end Triplets;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 204: | Line 204: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{libheader|ALGOL 68-primes}} |
{{libheader|ALGOL 68-primes}} |
||
< |
<syntaxhighlight lang="algol68">BEGIN # find numbers n where n-1, n+3 and n+5 are prime # |
||
# sieve the primes up to the maximum number for the task # |
# sieve the primes up to the maximum number for the task # |
||
PR read "primes.incl.a68" PR |
PR read "primes.incl.a68" PR |
||
Line 221: | Line 221: | ||
OD; |
OD; |
||
print( ( newline, "Found ", TOSTRING n count, " triplets", newline ) ) |
print( ( newline, "Found ", TOSTRING n count, " triplets", newline ) ) |
||
END</ |
END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 241: | Line 241: | ||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">lst: select 3..6000 'x |
||
-> all? @[prime? x-1 prime? x+3 prime? x+5] |
-> all? @[prime? x-1 prime? x+3 prime? x+5] |
||
loop split.every: 10 lst 'a -> |
loop split.every: 10 lst 'a -> |
||
print map a => [pad to :string & 5]</ |
print map a => [pad to :string & 5]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 256: | Line 256: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang="awk"> |
|||
<lang AWK> |
|||
# syntax: GAWK -f TRIPLET_OF_THREE_NUMBERS.AWK |
# syntax: GAWK -f TRIPLET_OF_THREE_NUMBERS.AWK |
||
BEGIN { |
BEGIN { |
||
Line 283: | Line 283: | ||
return(1) |
return(1) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 338: | Line 338: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
< |
<syntaxhighlight lang="basic">10 DEFINT A-Z: N=6000 |
||
20 DIM P(N+5) |
20 DIM P(N+5) |
||
30 FOR I=2 TO SQR(N) |
30 FOR I=2 TO SQR(N) |
||
Line 346: | Line 346: | ||
70 IF P(I-1) OR P(I+3) OR P(I+5) GOTO 90 |
70 IF P(I-1) OR P(I+3) OR P(I+5) GOTO 90 |
||
80 PRINT USING "####,: ####, ####, ####,";I;I-1;I+3;I+5 |
80 PRINT USING "####,: ####, ####, ####,";I;I-1;I+3;I+5 |
||
90 NEXT</ |
90 NEXT</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex'> 8: 7 11 13 |
<pre style='height:50ex'> 8: 7 11 13 |
||
Line 398: | Line 398: | ||
=={{header|BASIC256}}== |
=={{header|BASIC256}}== |
||
{{trans|FreeBASIC}} |
{{trans|FreeBASIC}} |
||
<syntaxhighlight lang="basic256"> |
|||
<lang BASIC256> |
|||
N = 6000 |
N = 6000 |
||
dim p(N+6) |
dim p(N+6) |
||
Line 418: | Line 418: | ||
next i |
next i |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 425: | Line 425: | ||
=={{header|BCPL}}== |
=={{header|BCPL}}== |
||
< |
<syntaxhighlight lang="bcpl">get "libhdr" |
||
manifest $( limit = 6000 $) |
manifest $( limit = 6000 $) |
||
Line 451: | Line 451: | ||
writef("%I4: %I4, %I4, %I4*N", i, i-1, i+3, i+5) |
writef("%I4: %I4, %I4, %I4*N", i, i-1, i+3, i+5) |
||
freevec(prime) |
freevec(prime) |
||
$)</ |
$)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex'> 8: 7, 11, 13 |
<pre style='height:50ex'> 8: 7, 11, 13 |
||
Line 501: | Line 501: | ||
=={{header|C}}== |
=={{header|C}}== |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <string.h> |
#include <string.h> |
||
Line 536: | Line 536: | ||
free(p); |
free(p); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex'> 8: 7, 11, 13 |
<pre style='height:50ex'> 8: 7, 11, 13 |
||
Line 587: | Line 587: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<syntaxhighlight lang="cpp">#include <iostream> |
||
#include <vector> |
#include <vector> |
||
Line 624: | Line 624: | ||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 8: 7, 11, 13 |
<pre> 8: 7, 11, 13 |
||
Line 675: | Line 675: | ||
=={{header|C#|CSharp}}== |
=={{header|C#|CSharp}}== |
||
How about some upper limits above 6000? |
How about some upper limits above 6000? |
||
< |
<syntaxhighlight lang="csharp">using System; using System.Collections.Generic; using System.Linq; |
||
using T3 = System.Tuple<int, int, int>; using static System.Console; |
using T3 = System.Tuple<int, int, int>; using static System.Console; |
||
class Program { static void Main() { |
class Program { static void Main() { |
||
Line 696: | Line 696: | ||
for (int k = s, i = j << 1; k < l; k += i) f[k] = true; } |
for (int k = s, i = j << 1; k < l; k += i) f[k] = true; } |
||
for (; j < l; lllj = llj, llj = lj, lj = j, j += 2) |
for (; j < l; lllj = llj, llj = lj, lj = j, j += 2) |
||
if (isPrT(lllj, lj, j)) yield return new T3(lllj, lj, j); } }</ |
if (isPrT(lllj, lj, j)) yield return new T3(lllj, lj, j); } }</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex'> "N": Prime Triplet Adjacent (to previous) |
<pre style='height:50ex'> "N": Prime Triplet Adjacent (to previous) |
||
Line 754: | Line 754: | ||
=={{header|CLU}}== |
=={{header|CLU}}== |
||
< |
<syntaxhighlight lang="clu">LIMIT = 6000 |
||
isqrt = proc (s: int) returns (int) |
isqrt = proc (s: int) returns (int) |
||
Line 799: | Line 799: | ||
end |
end |
||
end |
end |
||
end start_up</ |
end start_up</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex;'> 8: 7, 11, 13 |
<pre style='height:50ex;'> 8: 7, 11, 13 |
||
Line 849: | Line 849: | ||
=={{header|Comal}}== |
=={{header|Comal}}== |
||
< |
<syntaxhighlight lang="comal">0010 lim#:=6000 |
||
0020 DIM prime#(lim#) |
0020 DIM prime#(lim#) |
||
0030 FOR i#:=2 TO lim# DO prime#(i#):=TRUE |
0030 FOR i#:=2 TO lim# DO prime#(i#):=TRUE |
||
Line 860: | Line 860: | ||
0100 ENDIF |
0100 ENDIF |
||
0110 ENDFOR i# |
0110 ENDFOR i# |
||
0120 END</ |
0120 END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex;'> 8: 7, 11, 13 |
<pre style='height:50ex;'> 8: 7, 11, 13 |
||
Line 910: | Line 910: | ||
=={{header|Cowgol}}== |
=={{header|Cowgol}}== |
||
< |
<syntaxhighlight lang="cowgol">include "cowgol.coh"; |
||
const LIMIT := 6000; |
const LIMIT := 6000; |
||
Line 946: | Line 946: | ||
end if; |
end if; |
||
i := i + 1; |
i := i + 1; |
||
end loop;</ |
end loop;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex'>8: 7, 11, 13 |
<pre style='height:50ex'>8: 7, 11, 13 |
||
Line 997: | Line 997: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// Prime triplets: Nigel Galloway. May 18th., 2021 |
// Prime triplets: Nigel Galloway. May 18th., 2021 |
||
primes32()|>Seq.takeWhile((>)6000)|>Seq.filter(fun n->isPrime(n+4)&&isPrime(n+6))|>Seq.iter((+)1>>printf "%d "); printfn "" |
primes32()|>Seq.takeWhile((>)6000)|>Seq.filter(fun n->isPrime(n+4)&&isPrime(n+6))|>Seq.iter((+)1>>printf "%d "); printfn "" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,008: | Line 1,008: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-02-05}} |
{{works with|Factor|0.99 2021-02-05}} |
||
< |
<syntaxhighlight lang="factor">USING: combinators formatting grouping kernel math math.primes |
||
math.statistics sequences ; |
math.statistics sequences ; |
||
Line 1,018: | Line 1,018: | ||
"..., %4d, [%4d], __, __, %4d, __, %4d, ...\n" printf ; |
"..., %4d, [%4d], __, __, %4d, __, %4d, ...\n" printf ; |
||
6000 4,2-gaps [ first3 [ dup 1 + ] 2dip triplet. ] each</ |
6000 4,2-gaps [ first3 [ dup 1 + ] 2dip triplet. ] each</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style="height:14em"> |
<pre style="height:14em"> |
||
Line 1,071: | Line 1,071: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|Gforth}} |
{{works with|Gforth}} |
||
< |
<syntaxhighlight lang="forth">: prime? ( n -- ? ) here + c@ 0= ; |
||
: notprime! ( n -- ) here + 1 swap c! ; |
: notprime! ( n -- ) here + 1 swap c! ; |
||
Line 1,114: | Line 1,114: | ||
6000 main |
6000 main |
||
bye</ |
bye</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,171: | Line 1,171: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic"> |
||
Dim As Integer N = 6000 |
Dim As Integer N = 6000 |
||
Dim As Integer p(N) |
Dim As Integer p(N) |
||
Line 1,190: | Line 1,190: | ||
Next i |
Next i |
||
Sleep |
Sleep |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
8: 7 11 13 |
8: 7 11 13 |
||
Line 1,244: | Line 1,244: | ||
{{trans|Wren}} |
{{trans|Wren}} |
||
{{libheader|Go-rcu}} |
{{libheader|Go-rcu}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 1,268: | Line 1,268: | ||
} |
} |
||
fmt.Printf("\n%d such numbers found.\n", len(numbers)) |
fmt.Printf("\n%d such numbers found.\n", len(numbers)) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,324: | Line 1,324: | ||
=={{header|J}}== |
=={{header|J}}== |
||
< |
<syntaxhighlight lang="j">triplet=: (1 *./@p: _1 3 5+])"0 |
||
echo (0 _1 3 5+])"0 (triplet#]) i.6000 |
echo (0 _1 3 5+])"0 (triplet#]) i.6000 |
||
exit ''</ |
exit ''</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex'> 8 7 11 13 |
<pre style='height:50ex'> 8 7 11 13 |
||
Line 1,379: | Line 1,379: | ||
'''Works with gojq, the Go implementation of jq''' |
'''Works with gojq, the Go implementation of jq''' |
||
< |
<syntaxhighlight lang="jq">def is_prime: |
||
if . == 2 then true |
if . == 2 then true |
||
else |
else |
||
Line 1,390: | Line 1,390: | ||
end ; |
end ; |
||
range(3;6000) | select( all( .-1, .+3, .+5; is_prime))</ |
range(3;6000) | select( all( .-1, .+3, .+5; is_prime))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,403: | Line 1,403: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">using Primes |
||
makesprimetriplet(n) = all(isprime, [n - 1, n + 3, n + 5]) |
makesprimetriplet(n) = all(isprime, [n - 1, n + 3, n + 5]) |
||
println(" N Prime Triplet\n--------------------------") |
println(" N Prime Triplet\n--------------------------") |
||
foreach(n -> println(rpad(n, 6), [n - 1, n + 3, n + 5]), filter(makesprimetriplet, 2:6005)) |
foreach(n -> println(rpad(n, 6), [n - 1, n + 3, n + 5]), filter(makesprimetriplet, 2:6005)) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
N Prime Triplet |
N Prime Triplet |
||
Line 1,461: | Line 1,461: | ||
=={{header|Ksh}}== |
=={{header|Ksh}}== |
||
< |
<syntaxhighlight lang="ksh"> |
||
#!/bin/ksh |
#!/bin/ksh |
||
Line 1,511: | Line 1,511: | ||
IFS=${oldIFS} |
IFS=${oldIFS} |
||
unset arr |
unset arr |
||
done</ |
done</syntaxhighlight> |
||
{{out}}<pre> |
{{out}}<pre> |
||
8: 7,11,13 |
8: 7,11,13 |
||
Line 1,561: | Line 1,561: | ||
=={{header|MAD}}== |
=={{header|MAD}}== |
||
< |
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER |
||
BOOLEAN PRIME |
BOOLEAN PRIME |
||
DIMENSION PRIME(6005) |
DIMENSION PRIME(6005) |
||
Line 1,585: | Line 1,585: | ||
VECTOR VALUES FMT = $I4,3H =,3(I5)*$ |
VECTOR VALUES FMT = $I4,3H =,3(I5)*$ |
||
END OF PROGRAM </ |
END OF PROGRAM </syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex'> 8 = 7 11 13 |
<pre style='height:50ex'> 8 = 7 11 13 |
||
Line 1,635: | Line 1,635: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">Select[Range[5999], PrimeQ[# - 1] && PrimeQ[# + 3] && PrimeQ[# + 5] &]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{8, 14, 38, 68, 98, 104, 194, 224, 278, 308, 458, 614, 824, 854, 878, 1088, 1298, 1424, 1448, 1484, 1664, 1694, 1784, 1868, 1874, 1994, 2084, 2138, 2378, 2684, 2708, 2798, 3164, 3254, 3458, 3464, 3848, 4154, 4514, 4784, 5228, 5414, 5438, 5648, 5654, 5738}</pre> |
<pre>{8, 14, 38, 68, 98, 104, 194, 224, 278, 308, 458, 614, 824, 854, 878, 1088, 1298, 1424, 1448, 1484, 1664, 1694, 1784, 1868, 1874, 1994, 2084, 2138, 2378, 2684, 2708, 2798, 3164, 3254, 3458, 3464, 3848, 4154, 4514, 4784, 5228, 5414, 5438, 5648, 5654, 5738}</pre> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import strformat |
||
const |
const |
||
Line 1,666: | Line 1,666: | ||
inc count |
inc count |
||
echo &"\nFound {count} triplets for n < {N+1}."</ |
echo &"\nFound {count} triplets for n < {N+1}."</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,721: | Line 1,721: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
< |
<syntaxhighlight lang="perl">#!/usr/bin/perl |
||
use strict; |
use strict; |
||
Line 1,728: | Line 1,728: | ||
is_prime($_ - 4) and printf "%5d" x 4 . "\n", $_ - 3, $_ - 4, $_, $_ + 2 |
is_prime($_ - 4) and printf "%5d" x 4 . "\n", $_ - 3, $_ - 4, $_, $_ + 2 |
||
for @{ twin_primes( 6000 ) };</ |
for @{ twin_primes( 6000 ) };</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,780: | Line 1,780: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">function</span> <span style="color: #000000;">trio</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">({</span><span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">5</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">))=</span><span style="color: #000000;">3</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">trio</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">({</span><span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">5</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">))=</span><span style="color: #000000;">3</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">6000</span><span style="color: #0000FF;">),</span><span style="color: #000000;">trio</span><span style="color: #0000FF;">)</span> |
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">6000</span><span style="color: #0000FF;">),</span><span style="color: #000000;">trio</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d found: %V\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">)})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d found: %V\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">)})</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<small>(assumes you can add {-1,3,5} to each number in your head easily enough)</small> |
<small>(assumes you can add {-1,3,5} to each number in your head easily enough)</small> |
||
Line 1,792: | Line 1,792: | ||
=={{header|PL/M}}== |
=={{header|PL/M}}== |
||
< |
<syntaxhighlight lang="plm">100H: |
||
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS; |
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS; |
||
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT; |
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT; |
||
Line 1,852: | Line 1,852: | ||
END; |
END; |
||
CALL EXIT; |
CALL EXIT; |
||
EOF</ |
EOF</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex'>8: 7, 11, 13 |
<pre style='height:50ex'>8: 7, 11, 13 |
||
Line 1,904: | Line 1,904: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{trans|FreeBASIC}} |
{{trans|FreeBASIC}} |
||
< |
<syntaxhighlight lang="python"> |
||
#!/usr/bin/python3 |
#!/usr/bin/python3 |
||
Line 1,921: | Line 1,921: | ||
else: |
else: |
||
print(i, ': ', i-1, ' ', i+3, ' ', i+5) |
print(i, ': ', i-1, ' ', i+3, ' ', i+5) |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
Similar a la entrada de FreeBASIC. |
Similar a la entrada de FreeBASIC. |
||
Line 1,928: | Line 1,928: | ||
=={{header|Quackery}}== |
=={{header|Quackery}}== |
||
< |
<syntaxhighlight lang="quackery"> [ 1 swap times [ i 1+ * ] ] is ! ( n --> n ) |
||
[ dup 2 < iff |
[ dup 2 < iff |
||
Line 1,943: | Line 1,943: | ||
else drop ] |
else drop ] |
||
else drop ] |
else drop ] |
||
echo</ |
echo</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,953: | Line 1,953: | ||
A weird combination of [[Cousin primes]] and [[Twin primes]] that are siblings, but known by their neighbor.... I shall dub these Alabama primes. |
A weird combination of [[Cousin primes]] and [[Twin primes]] that are siblings, but known by their neighbor.... I shall dub these Alabama primes. |
||
<lang |
<syntaxhighlight lang="raku" line>say "{.[0]+1}: ",$_ for grep *.all.is-prime, ^6000 .race.map: { $_-1, $_+3, $_+5 };</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>8: (7 11 13) |
<pre>8: (7 11 13) |
||
Line 2,003: | Line 2,003: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
< |
<syntaxhighlight lang="rexx">/*REXX pgm finds prime triplets: n-1, n+3, n+5 are primes, and n < some specified #.*/ |
||
parse arg hi cols . /*obtain optional argument from the CL.*/ |
parse arg hi cols . /*obtain optional argument from the CL.*/ |
||
if hi=='' | hi=="," then hi= 6000 /*Not specified? Then use the default.*/ |
if hi=='' | hi=="," then hi= 6000 /*Not specified? Then use the default.*/ |
||
Line 2,047: | Line 2,047: | ||
end /*k*/ /* [↑] only process numbers ≤ √ J */ |
end /*k*/ /* [↑] only process numbers ≤ √ J */ |
||
#= #+1; @.#= j; sq.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */ |
#= #+1; @.#= j; sq.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */ |
||
end /*j*/; return</ |
end /*j*/; return</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 2,070: | Line 2,070: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
load "stdlib.ring" |
load "stdlib.ring" |
||
see "working..." + nl |
see "working..." + nl |
||
Line 2,092: | Line 2,092: | ||
see "Found " + row + " prime triplets" + nl |
see "Found " + row + " prime triplets" + nl |
||
see "done..." + nl |
see "done..." + nl |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,149: | Line 2,149: | ||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
< |
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i"; |
||
const func boolean: isPrime (in integer: number) is func |
const func boolean: isPrime (in integer: number) is func |
||
Line 2,183: | Line 2,183: | ||
end for; |
end for; |
||
writeln("\nFound " <& count <& " triplets for n < 6000."); |
writeln("\nFound " <& count <& " triplets for n < 6000."); |
||
end func;</ |
end func;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,239: | Line 2,239: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">^6000 -> grep {|n| [-1, 3, 5].all {|k| n + k -> is_prime } }.say</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,248: | Line 2,248: | ||
=={{header|True BASIC}}== |
=={{header|True BASIC}}== |
||
{{trans|FreeBASIC}} |
{{trans|FreeBASIC}} |
||
< |
<syntaxhighlight lang="basic"> |
||
LET n = 6000 |
LET n = 6000 |
||
Line 2,270: | Line 2,270: | ||
NEXT i |
NEXT i |
||
END |
END |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,278: | Line 2,278: | ||
=={{header|Vlang}}== |
=={{header|Vlang}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="vlang">import math |
||
const n = 6000 |
const n = 6000 |
||
Line 2,299: | Line 2,299: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
<pre> |
<pre> |
||
Similar to Go |
Similar to Go |
||
Line 2,307: | Line 2,307: | ||
{{libheader|Wren-math}} |
{{libheader|Wren-math}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/math" for Int |
||
import "/fmt" for Fmt |
import "/fmt" for Fmt |
||
Line 2,319: | Line 2,319: | ||
} |
} |
||
for (n in numbers) Fmt.print("$,6d => $,6d", n, [n-1, n+3, n+5]) |
for (n in numbers) Fmt.print("$,6d => $,6d", n, [n-1, n+3, n+5]) |
||
System.print("\nFound %(numbers.count) such numbers.")</ |
System.print("\nFound %(numbers.count) such numbers.")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,375: | Line 2,375: | ||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">func IsPrime(N); \Return 'true' if N is prime |
||
int N, I; |
int N, I; |
||
[if N <= 2 then return N = 2; |
[if N <= 2 then return N = 2; |
||
Line 2,401: | Line 2,401: | ||
Text(0, " prime triplets found below 6000. |
Text(0, " prime triplets found below 6000. |
||
"); |
"); |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,420: | Line 2,420: | ||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Triplet_of_three_numbers |
||
// by Galileo, 04/2022 |
// by Galileo, 04/2022 |
||
Line 2,436: | Line 2,436: | ||
for i = 3 to N |
for i = 3 to N |
||
if not (p(i-1) or p(i+3) or p(i+5)) print i, ": ", i-1, " ", i+3, " ", i+5 |
if not (p(i-1) or p(i+3) or p(i+5)) print i, ": ", i-1, " ", i+3, " ", i+5 |
||
next</ |
next</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>8: 7 11 13 |
<pre>8: 7 11 13 |