Triplet of three numbers: Difference between revisions
m
syntax highlighting fixup automation
No edit summary |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 8:
{{trans|Python}}
<
V p = [0B] * 6000
Line 20:
L.continue
E
print(f:‘{i:4}: {i - 1:4} {i + 3:4} {i + 5:4}’)</
{{out}}
Line 74:
=={{header|Action!}}==
{{libheader|Action! Sieve of Eratosthenes}}
<
PROC Main()
Line 91:
OD
PrintF("%E%EThere are %I triplets",count)
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Triplet_of_three_numbers.png Screenshot from Atari 8-bit computer]
Line 107:
=={{header|Ada}}==
<
procedure Triplets is
Line 151:
end if;
end loop;
end Triplets;</
{{out}}
<pre>
Line 204:
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<
# sieve the primes up to the maximum number for the task #
PR read "primes.incl.a68" PR
Line 221:
OD;
print( ( newline, "Found ", TOSTRING n count, " triplets", newline ) )
END</
{{out}}
<pre>
Line 241:
=={{header|Arturo}}==
<
-> all? @[prime? x-1 prime? x+3 prime? x+5]
loop split.every: 10 lst 'a ->
print map a => [pad to :string & 5]</
{{out}}
Line 256:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f TRIPLET_OF_THREE_NUMBERS.AWK
BEGIN {
Line 283:
return(1)
}
</syntaxhighlight>
{{out}}
<pre>
Line 338:
=={{header|BASIC}}==
<
20 DIM P(N+5)
30 FOR I=2 TO SQR(N)
Line 346:
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
90 NEXT</
{{out}}
<pre style='height:50ex'> 8: 7 11 13
Line 398:
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic256">
N = 6000
dim p(N+6)
Line 418:
next i
end
</syntaxhighlight>
{{out}}
<pre>
Line 425:
=={{header|BCPL}}==
<
manifest $( limit = 6000 $)
Line 451:
writef("%I4: %I4, %I4, %I4*N", i, i-1, i+3, i+5)
freevec(prime)
$)</
{{out}}
<pre style='height:50ex'> 8: 7, 11, 13
Line 501:
=={{header|C}}==
<
#include <stdlib.h>
#include <string.h>
Line 536:
free(p);
return 0;
}</
{{out}}
<pre style='height:50ex'> 8: 7, 11, 13
Line 587:
=={{header|C++}}==
{{trans|C}}
<
#include <vector>
Line 624:
return 0;
}</
{{out}}
<pre> 8: 7, 11, 13
Line 675:
=={{header|C#|CSharp}}==
How about some upper limits above 6000?
<
using T3 = System.Tuple<int, int, int>; using static System.Console;
class Program { static void Main() {
Line 696:
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)
if (isPrT(lllj, lj, j)) yield return new T3(lllj, lj, j); } }</
{{out}}
<pre style='height:50ex'> "N": Prime Triplet Adjacent (to previous)
Line 754:
=={{header|CLU}}==
<
isqrt = proc (s: int) returns (int)
Line 799:
end
end
end start_up</
{{out}}
<pre style='height:50ex;'> 8: 7, 11, 13
Line 849:
=={{header|Comal}}==
<
0020 DIM prime#(lim#)
0030 FOR i#:=2 TO lim# DO prime#(i#):=TRUE
Line 860:
0100 ENDIF
0110 ENDFOR i#
0120 END</
{{out}}
<pre style='height:50ex;'> 8: 7, 11, 13
Line 910:
=={{header|Cowgol}}==
<
const LIMIT := 6000;
Line 946:
end if;
i := i + 1;
end loop;</
{{out}}
<pre style='height:50ex'>8: 7, 11, 13
Line 997:
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
<
// 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 ""
</syntaxhighlight>
{{out}}
<pre>
Line 1,008:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<
math.statistics sequences ;
Line 1,018:
"..., %4d, [%4d], __, __, %4d, __, %4d, ...\n" printf ;
6000 4,2-gaps [ first3 [ dup 1 + ] 2dip triplet. ] each</
{{out}}
<pre style="height:14em">
Line 1,071:
=={{header|Forth}}==
{{works with|Gforth}}
<
: notprime! ( n -- ) here + 1 swap c! ;
Line 1,114:
6000 main
bye</
{{out}}
Line 1,171:
=={{header|FreeBASIC}}==
<
Dim As Integer N = 6000
Dim As Integer p(N)
Line 1,190:
Next i
Sleep
</syntaxhighlight>
<pre>
8: 7 11 13
Line 1,244:
{{trans|Wren}}
{{libheader|Go-rcu}}
<
import (
Line 1,268:
}
fmt.Printf("\n%d such numbers found.\n", len(numbers))
}</
{{out}}
Line 1,324:
=={{header|J}}==
<
echo (0 _1 3 5+])"0 (triplet#]) i.6000
exit ''</
{{out}}
<pre style='height:50ex'> 8 7 11 13
Line 1,379:
'''Works with gojq, the Go implementation of jq'''
<
if . == 2 then true
else
Line 1,390:
end ;
range(3;6000) | select( all( .-1, .+3, .+5; is_prime))</
{{out}}
<pre>
Line 1,403:
=={{header|Julia}}==
<
makesprimetriplet(n) = all(isprime, [n - 1, n + 3, n + 5])
println(" N Prime Triplet\n--------------------------")
foreach(n -> println(rpad(n, 6), [n - 1, n + 3, n + 5]), filter(makesprimetriplet, 2:6005))
</
<pre>
N Prime Triplet
Line 1,461:
=={{header|Ksh}}==
<
#!/bin/ksh
Line 1,511:
IFS=${oldIFS}
unset arr
done</
{{out}}<pre>
8: 7,11,13
Line 1,561:
=={{header|MAD}}==
<
BOOLEAN PRIME
DIMENSION PRIME(6005)
Line 1,585:
VECTOR VALUES FMT = $I4,3H =,3(I5)*$
END OF PROGRAM </
{{out}}
<pre style='height:50ex'> 8 = 7 11 13
Line 1,635:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
{{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>
=={{header|Nim}}==
<
const
Line 1,666:
inc count
echo &"\nFound {count} triplets for n < {N+1}."</
{{out}}
Line 1,721:
=={{header|Perl}}==
{{libheader|ntheory}}
<
use strict;
Line 1,728:
is_prime($_ - 4) and printf "%5d" x 4 . "\n", $_ - 3, $_ - 4, $_, $_ + 2
for @{ twin_primes( 6000 ) };</
{{out}}
<pre>
Line 1,780:
=={{header|Phix}}==
<!--<
<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: #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>
<!--</
{{out}}
<small>(assumes you can add {-1,3,5} to each number in your head easily enough)</small>
Line 1,792:
=={{header|PL/M}}==
<
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
Line 1,852:
END;
CALL EXIT;
EOF</
{{out}}
<pre style='height:50ex'>8: 7, 11, 13
Line 1,904:
=={{header|Python}}==
{{trans|FreeBASIC}}
<
#!/usr/bin/python3
Line 1,921:
else:
print(i, ': ', i-1, ' ', i+3, ' ', i+5)
</syntaxhighlight>
<pre>
Similar a la entrada de FreeBASIC.
Line 1,928:
=={{header|Quackery}}==
<
[ dup 2 < iff
Line 1,943:
else drop ]
else drop ]
echo</
{{out}}
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.
<syntaxhighlight lang="raku"
{{out}}
<pre>8: (7 11 13)
Line 2,003:
=={{header|REXX}}==
<
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 6000 /*Not specified? Then use the default.*/
Line 2,047:
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; sq.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return</
{{out|output|text= when using the default inputs:}}
<pre>
Line 2,070:
=={{header|Ring}}==
<
load "stdlib.ring"
see "working..." + nl
Line 2,092:
see "Found " + row + " prime triplets" + nl
see "done..." + nl
</syntaxhighlight>
{{out}}
<pre>
Line 2,149:
=={{header|Seed7}}==
<
const func boolean: isPrime (in integer: number) is func
Line 2,183:
end for;
writeln("\nFound " <& count <& " triplets for n < 6000.");
end func;</
{{out}}
<pre>
Line 2,239:
=={{header|Sidef}}==
<
{{out}}
<pre>
Line 2,248:
=={{header|True BASIC}}==
{{trans|FreeBASIC}}
<
LET n = 6000
Line 2,270:
NEXT i
END
</syntaxhighlight>
{{out}}
<pre>
Line 2,278:
=={{header|Vlang}}==
{{trans|Python}}
<
const n = 6000
Line 2,299:
}
}
}</
<pre>
Similar to Go
Line 2,307:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<
import "/fmt" for Fmt
Line 2,319:
}
for (n in numbers) Fmt.print("$,6d => $,6d", n, [n-1, n+3, n+5])
System.print("\nFound %(numbers.count) such numbers.")</
{{out}}
Line 2,375:
=={{header|XPL0}}==
<
int N, I;
[if N <= 2 then return N = 2;
Line 2,401:
Text(0, " prime triplets found below 6000.
");
]</
{{out}}
Line 2,420:
=={{header|Yabasic}}==
{{trans|Python}}
<
// by Galileo, 04/2022
Line 2,436:
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
next</
{{out}}
<pre>8: 7 11 13
|