Strange unique prime triplets: Difference between revisions

Content deleted Content added
Trizen (talk | contribs)
Added Sidef
Thundergnat (talk | contribs)
m syntax highlighting fixup automation
Line 12: Line 12:
{{trans|Python}}
{{trans|Python}}


<lang 11l>F primes_upto(limit)
<syntaxhighlight lang="11l">F primes_upto(limit)
V is_prime = [0B] * 2 [+] [1B] * (limit - 1)
V is_prime = [0B] * 2 [+] [1B] * (limit - 1)
L(n) 0 .< Int(limit ^ 0.5 + 1.5)
L(n) 0 .< Int(limit ^ 0.5 + 1.5)
Line 37: Line 37:


V mx = 1'000
V mx = 1'000
print("\nIf n, m, p < #. finds #.".format(mx, strange_triplets(mx).len))</lang>
print("\nIf n, m, p < #. finds #.".format(mx, strange_triplets(mx).len))</syntaxhighlight>


{{out}}
{{out}}
Line 89: Line 89:
=={{header|Action!}}==
=={{header|Action!}}==
{{libheader|Action! Sieve of Eratosthenes}}
{{libheader|Action! Sieve of Eratosthenes}}
<lang Action!>INCLUDE "H6:SIEVE.ACT"
<syntaxhighlight lang="action!">INCLUDE "H6:SIEVE.ACT"


PROC Main()
PROC Main()
Line 122: Line 122:
OD
OD
PrintF("%EThere are %I prime triplets",count)
PrintF("%EThere are %I prime triplets",count)
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Strange_unique_prime_triplets.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Strange_unique_prime_triplets.png Screenshot from Atari 8-bit computer]
Line 147: Line 147:
{{Trans|Algol W}} which is based on {{Trans|Wren}}
{{Trans|Algol W}} which is based on {{Trans|Wren}}
{{libheader|ALGOL 68-primes}}
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # find some strange unique primes - triplets of primes n, m, p #
<syntaxhighlight lang="algol68">BEGIN # find some strange unique primes - triplets of primes n, m, p #
# where n + m + p is also prime and n =/= m =/= p #
# where n + m + p is also prime and n =/= m =/= p #
# we need to find the strange unique prime triplets below 1000 #
# we need to find the strange unique prime triplets below 1000 #
Line 188: Line 188:
print( ( "Found ", whole( c30, -6 ), " strange unique prime triplets up to 30", newline ) );
print( ( "Found ", whole( c30, -6 ), " strange unique prime triplets up to 30", newline ) );
print( ( "Found ", whole( s count, -6 ), " strange unique prime triplets up to 1000", newline ) )
print( ( "Found ", whole( s count, -6 ), " strange unique prime triplets up to 1000", newline ) )
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 239: Line 239:
=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
Based on {{Trans|Wren}}
Based on {{Trans|Wren}}
<lang algolw>begin % find some strange unique primes - triplets of primes n, m, p %
<syntaxhighlight lang="algolw">begin % find some strange unique primes - triplets of primes n, m, p %
% where n + m + p is also prime and n =/= m =/= p %
% where n + m + p is also prime and n =/= m =/= p %
% sets p( 1 :: n ) to a sieve of primes up to n %
% sets p( 1 :: n ) to a sieve of primes up to n %
Line 289: Line 289:
write( i_w := 3, s_w := 0, "Found ", sCount, " strange unique prime triplets up to 1000" );
write( i_w := 3, s_w := 0, "Found ", sCount, " strange unique prime triplets up to 1000" );
end
end
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 339: Line 339:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f STRANGE_UNIQUE_PRIME_TRIPLETS.AWK
# syntax: GAWK -f STRANGE_UNIQUE_PRIME_TRIPLETS.AWK
# converted from Go
# converted from Go
Line 380: Line 380:
return(1)
return(1)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 431: Line 431:


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdbool.h>
<syntaxhighlight lang="c">#include <stdbool.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
Line 524: Line 524:


return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Strange unique prime triplets < 30:
<pre>Strange unique prime triplets < 30:
Line 575: Line 575:
=={{header|C#|CSharp}}==
=={{header|C#|CSharp}}==
Just for fun, <30 sorted by sum, instead of order generated. One might think one should include the sieve generation time, but it is orders of magnitude smaller than the permute/sum time for these relatively low numbers.
Just for fun, <30 sorted by sum, instead of order generated. One might think one should include the sieve generation time, but it is orders of magnitude smaller than the permute/sum time for these relatively low numbers.
<lang csharp>using System; using System.Collections.Generic; using static System.Console; using System.Linq; using DT = System.DateTime;
<syntaxhighlight lang="csharp">using System; using System.Collections.Generic; using static System.Console; using System.Linq; using DT = System.DateTime;


class Program { static void Main(string[] args) { string s;
class Program { static void Main(string[] args) { string s;
Line 597: Line 597:
if (!flags[j]) { yield return j;
if (!flags[j]) { yield return j;
for (int k = sq; k <= lim; k += j) flags[k] = true; }
for (int k = sq; k <= lim; k += j) flags[k] = true; }
for (; j <= lim; j++) if (!flags[j]) yield return j; } }</lang>
for (; j <= lim; j++) if (!flags[j]) yield return j; } }</syntaxhighlight>
{{out}}
{{out}}
Timings from tio.run
Timings from tio.run
Line 650: Line 650:


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <iomanip>
<syntaxhighlight lang="cpp">#include <iomanip>
#include <iostream>
#include <iostream>
#include <vector>
#include <vector>
Line 710: Line 710:
strange_unique_prime_triplets(1000, false);
strange_unique_prime_triplets(1000, false);
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 766: Line 766:
{{libheader| System.SysUtils}}
{{libheader| System.SysUtils}}
{{Trans|Go}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Strange_primes;
program Strange_primes;


Line 852: Line 852:
writeln('There are ', cs, ' unique prime triples under 1,000 which sum to a prime.');
writeln('There are ', cs, ' unique prime triples under 1,000 which sum to a prime.');
readln;
readln;
end.</lang>
end.</syntaxhighlight>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
This task uses [[Extensible_prime_generator#The_functions|Extensible Prime Generator (F#)]].<br>
This task uses [[Extensible_prime_generator#The_functions|Extensible Prime Generator (F#)]].<br>
<lang fsharp>
<syntaxhighlight lang="fsharp">
// Strange unique prime triplets. Nigel Galloway: March 12th., 2021
// Strange unique prime triplets. Nigel Galloway: March 12th., 2021
let sP n=let N=primes32()|>Seq.takeWhile((>)n)|>Array.ofSeq
let sP n=let N=primes32()|>Seq.takeWhile((>)n)|>Array.ofSeq
Line 863: Line 863:
printfn "%d" (Seq.length(sP 1000))
printfn "%d" (Seq.length(sP 1000))
printfn "%d" (Seq.length(sP 10000))
printfn "%d" (Seq.length(sP 10000))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 870: Line 870:
</pre>
</pre>
=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: formatting io kernel math math.combinatorics math.primes
<syntaxhighlight lang="factor">USING: formatting io kernel math math.combinatorics math.primes
sequences tools.memory.private ;
sequences tools.memory.private ;


Line 886: Line 886:
30 strange
30 strange
1,000 count-strange commas nl
1,000 count-strange commas nl
"Found %s strange prime triplets with n, m, p < 1,000.\n" printf</lang>
"Found %s strange prime triplets with n, m, p < 1,000.\n" printf</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 936: Line 936:


=={{header|Fermat}}==
=={{header|Fermat}}==
<lang fermat>Function IsSUPT(n,m,p) =
<syntaxhighlight lang="fermat">Function IsSUPT(n,m,p) =
if Isprime(n) and Isprime(m) and Isprime(p) and Isprime(n+m+p) then 1 else 0 fi.
if Isprime(n) and Isprime(m) and Isprime(p) and Isprime(n+m+p) then 1 else 0 fi.


Line 945: Line 945:
od;
od;
od;
od;
od</lang>
od</syntaxhighlight>
I'll leave the stretch goal for someone else.
I'll leave the stretch goal for someone else.


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
Use the function at [[Primality by trial division#FreeBASIC]] as an include; I can't be bothered reproducing it here.
Use the function at [[Primality by trial division#FreeBASIC]] as an include; I can't be bothered reproducing it here.
<lang freebasic>#include"isprime.bas"
<syntaxhighlight lang="freebasic">#include"isprime.bas"


dim as uinteger c = 0
dim as uinteger c = 0
Line 968: Line 968:
next p
next p


print "There are ";c;" triples below 1000."</lang>
print "There are ";c;" triples below 1000."</syntaxhighlight>
{{out}}<pre>3 + 5 + 11 = 19
{{out}}<pre>3 + 5 + 11 = 19
3 + 5 + 23 = 31
3 + 5 + 23 = 31
Line 1,015: Line 1,015:
=={{header|Forth}}==
=={{header|Forth}}==
{{works with|Gforth}}
{{works with|Gforth}}
<lang forth>: prime? ( n -- ? ) here + c@ 0= ;
<syntaxhighlight lang="forth">: prime? ( n -- ? ) here + c@ 0= ;
: notprime! ( n -- ) here + 1 swap c! ;
: notprime! ( n -- ) here + 1 swap c! ;


Line 1,084: Line 1,084:
." Count of strange unique prime triplets < 1000: "
." Count of strange unique prime triplets < 1000: "
1000 count_strange_unique_prime_triplets . cr
1000 count_strange_unique_prime_triplets . cr
bye</lang>
bye</syntaxhighlight>


{{out}}
{{out}}
Line 1,145: Line 1,145:
===Basic===
===Basic===
{{trans|Wren}}
{{trans|Wren}}
<lang go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 1,220: Line 1,220:
cs := commatize(strangePrimes(999, true))
cs := commatize(strangePrimes(999, true))
fmt.Printf("\nThere are %s unique prime triples under 1,000 which sum to a prime.\n", cs)
fmt.Printf("\nThere are %s unique prime triples under 1,000 which sum to a prime.\n", cs)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,273: Line 1,273:
===Faster===
===Faster===
{{trans|Wren}}
{{trans|Wren}}
<lang go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 1,357: Line 1,357:
cs := commatize(strangePrimes(999, true))
cs := commatize(strangePrimes(999, true))
fmt.Printf("\nThere are %s unique prime triples under 1,000 which sum to a prime.\n", cs)
fmt.Printf("\nThere are %s unique prime triples under 1,000 which sum to a prime.\n", cs)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,363: Line 1,363:


=={{header|Java}}==
=={{header|Java}}==
<lang java>import java.util.*;
<syntaxhighlight lang="java">import java.util.*;


public class StrangeUniquePrimeTriplets {
public class StrangeUniquePrimeTriplets {
Line 1,423: Line 1,423:
return sieve;
return sieve;
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,481: Line 1,481:


See e.g. [[Erd%C5%91s-primes#jq]] for a suitable implementation of `is_prime`.
See e.g. [[Erd%C5%91s-primes#jq]] for a suitable implementation of `is_prime`.
<lang jq>def count(s): reduce s as $x (null; .+1);
<syntaxhighlight lang="jq">def count(s): reduce s as $x (null; .+1);


def task($n):
def task($n):
Line 1,493: Line 1,493:


task(30),
task(30),
"\nStretch goal: \(count(task(1000)))"</lang>
"\nStretch goal: \(count(task(1000)))"</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,542: Line 1,542:
</pre>
</pre>
=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using Primes
<syntaxhighlight lang="julia">using Primes


function prime_sum_prime_triplets_to(N, verbose=false)
function prime_sum_prime_triplets_to(N, verbose=false)
Line 1,569: Line 1,569:
@time prime_sum_prime_triplets_to(10000)
@time prime_sum_prime_triplets_to(10000)
@time prime_sum_prime_triplets_to(100000)
@time prime_sum_prime_triplets_to(100000)
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
Triplet Sum
Triplet Sum
Line 1,632: Line 1,632:


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>p = Prime[Range@PrimePi[30]];
<syntaxhighlight lang="mathematica">p = Prime[Range@PrimePi[30]];
Select[Subsets[p, {3}], Total/*PrimeQ]
Select[Subsets[p, {3}], Total/*PrimeQ]


p = Prime[Range@PrimePi[1000]];
p = Prime[Range@PrimePi[1000]];
Length[Select[Subsets[p, {3}], Total/*PrimeQ]]</lang>
Length[Select[Subsets[p, {3}], Total/*PrimeQ]]</syntaxhighlight>
{{out}}
{{out}}
<pre>{{3,5,11},{3,5,23},{3,5,29},{3,7,13},{3,7,19},{3,11,17},{3,11,23},{3,11,29},{3,17,23},{5,7,11},{5,7,17},{5,7,19},{5,7,29},{5,11,13},{5,13,19},{5,13,23},{5,13,29},{5,17,19},{5,19,23},{5,19,29},{7,11,13},{7,11,19},{7,11,23},{7,11,29},{7,13,17},{7,13,23},{7,17,19},{7,17,23},{7,17,29},{7,23,29},{11,13,17},{11,13,19},{11,13,23},{11,13,29},{11,17,19},{11,19,23},{11,19,29},{13,17,23},{13,17,29},{13,19,29},{17,19,23},{19,23,29}}
<pre>{{3,5,11},{3,5,23},{3,5,29},{3,7,13},{3,7,19},{3,11,17},{3,11,23},{3,11,29},{3,17,23},{5,7,11},{5,7,17},{5,7,19},{5,7,29},{5,11,13},{5,13,19},{5,13,23},{5,13,29},{5,17,19},{5,19,23},{5,19,29},{7,11,13},{7,11,19},{7,11,23},{7,11,29},{7,13,17},{7,13,23},{7,17,19},{7,17,23},{7,17,29},{7,23,29},{11,13,17},{11,13,19},{11,13,23},{11,13,29},{11,17,19},{11,19,23},{11,19,29},{13,17,23},{13,17,29},{13,19,29},{17,19,23},{19,23,29}}
Line 1,642: Line 1,642:


=={{header|Nim}}==
=={{header|Nim}}==
<lang Nim>import strformat, strutils, sugar
<syntaxhighlight lang="nim">import strformat, strutils, sugar


func isPrime(n: Positive): bool =
func isPrime(n: Positive): bool =
Line 1,680: Line 1,680:
var count = 0
var count = 0
for _ in Primes1000.triplets(): inc count
for _ in Primes1000.triplets(): inc count
echo "Count of strange unique prime triplets for n < m < p < 1000: ", ($count).insertSep()</lang>
echo "Count of strange unique prime triplets for n < m < p < 1000: ", ($count).insertSep()</syntaxhighlight>


{{out}}
{{out}}
Line 1,731: Line 1,731:
=={{header|Pascal}}==
=={{header|Pascal}}==
{{works with|Free Pascal}}
{{works with|Free Pascal}}
<lang pascal>program PrimeTriplets;
<syntaxhighlight lang="pascal">program PrimeTriplets;
//Free Pascal Compiler version 3.2.1 [2020/11/03] for x86_64fpc 3.2.1
//Free Pascal Compiler version 3.2.1 [2020/11/03] for x86_64fpc 3.2.1
{$IFDEF FPC}
{$IFDEF FPC}
Line 1,874: Line 1,874:
Check_Limit(10000);
Check_Limit(10000);
//Check_Limit(MAXZAHL);
//Check_Limit(MAXZAHL);
END.</lang>
END.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,929: Line 1,929:
=={{header|Perl}}==
=={{header|Perl}}==
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>use strict;
<syntaxhighlight lang="perl">use strict;
use warnings;
use warnings;
use List::Util 'sum';
use List::Util 'sum';
Line 1,938: Line 1,938:
printf "Found %d strange unique prime triplets up to $n.\n",
printf "Found %d strange unique prime triplets up to $n.\n",
scalar grep { is_prime(sum @$_) } combinations(primes($n), 3);
scalar grep { is_prime(sum @$_) } combinations(primes($n), 3);
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Found 42 strange unique prime triplets up to 30.
<pre>Found 42 strange unique prime triplets up to 30.
Line 1,944: Line 1,944:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"0.8.4"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"0.8.4"</span><span style="color: #0000FF;">)</span>
Line 2,014: Line 2,014:
<span style="color: #000000;">strange_triplets</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">strange_triplets</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">strange_triplets</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10000</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">strange_triplets</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10000</span><span style="color: #0000FF;">)</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 2,034: Line 2,034:
Using [https://docs.sympy.org/latest/modules/ntheory.html#sympy.ntheory.generate.Sieve.primerange sympy.primerange].
Using [https://docs.sympy.org/latest/modules/ntheory.html#sympy.ntheory.generate.Sieve.primerange sympy.primerange].


<lang python>from sympy import primerange
<syntaxhighlight lang="python">from sympy import primerange


def strange_triplets(mx: int = 30) -> None:
def strange_triplets(mx: int = 30) -> None:
Line 2,049: Line 2,049:


mx = 1_000
mx = 1_000
print(f"\nIf n, m, p < {mx:_} finds {sum(1 for _ in strange_triplets(mx)):_}")</lang>
print(f"\nIf n, m, p < {mx:_} finds {sum(1 for _ in strange_triplets(mx)):_}")</syntaxhighlight>


{{out}}
{{out}}
Line 2,099: Line 2,099:
=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
<lang perl6># 20210312 Raku programming solution
<syntaxhighlight lang="raku" line># 20210312 Raku programming solution


for 30, 1000 -> \k {
for 30, 1000 -> \k {
Line 2,105: Line 2,105:
say "Found ", +$_, " strange unique prime triplets up to ", k
say "Found ", +$_, " strange unique prime triplets up to ", k
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,113: Line 2,113:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program finds/lists triplet strange primes (<HI) where the triplets' sum is prime*/
<syntaxhighlight lang="rexx">/*REXX program finds/lists triplet strange primes (<HI) where the triplets' sum is prime*/
parse arg hi . /*obtain optional argument from the CL.*/
parse arg hi . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 30 /*Not specified? Then use the default.*/
if hi=='' | hi=="," then hi= 30 /*Not specified? Then use the default.*/
Line 2,153: Line 2,153:
end /*k*/ /* [↑] only process numbers ≤ √ J */
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; s.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
#= #+1; @.#= j; s.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return</lang>
end /*j*/; return</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>
Line 2,211: Line 2,211:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
load "stdlib.ring"
load "stdlib.ring"


Line 2,233: Line 2,233:


see "done..." + nl
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,285: Line 2,285:


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>fn prime_sieve(limit: usize) -> Vec<bool> {
<syntaxhighlight lang="rust">fn prime_sieve(limit: usize) -> Vec<bool> {
let mut sieve = vec![true; limit];
let mut sieve = vec![true; limit];
if limit > 0 {
if limit > 0 {
Line 2,355: Line 2,355:
strange_unique_prime_triplets(30, true);
strange_unique_prime_triplets(30, true);
strange_unique_prime_triplets(1000, false);
strange_unique_prime_triplets(1000, false);
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,407: Line 2,407:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>for n in (30, 1000) {
<syntaxhighlight lang="ruby">for n in (30, 1000) {
var triplets = []
var triplets = []
combinations(n.primes, 3, {|*a|
combinations(n.primes, 3, {|*a|
Line 2,417: Line 2,417:
}
}
printf("Found %d strange unique prime triplets up to %s.\n", triplets.len, n)
printf("Found %d strange unique prime triplets up to %s.\n", triplets.len, n)
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,433: Line 2,433:


=={{header|Swift}}==
=={{header|Swift}}==
<lang swift>import Foundation
<syntaxhighlight lang="swift">import Foundation


func primeSieve(limit: Int) -> [Bool] {
func primeSieve(limit: Int) -> [Bool] {
Line 2,501: Line 2,501:


strangeUniquePrimeTriplets(limit: 30, verbose: true)
strangeUniquePrimeTriplets(limit: 30, verbose: true)
strangeUniquePrimeTriplets(limit: 1000, verbose: false)</lang>
strangeUniquePrimeTriplets(limit: 1000, verbose: false)</syntaxhighlight>


{{out}}
{{out}}
Line 2,556: Line 2,556:
=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
{{trans|C#}}
{{trans|C#}}
<lang vbnet>Imports DT = System.DateTime
<syntaxhighlight lang="vbnet">Imports DT = System.DateTime


Module Module1
Module Module1
Line 2,630: Line 2,630:
End Sub
End Sub


End Module</lang>
End Module</syntaxhighlight>
{{out}}
{{out}}
<pre>Same as C#</pre>
<pre>Same as C#</pre>
Line 2,639: Line 2,639:
{{libheader|Wren-trait}}
{{libheader|Wren-trait}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Int
<syntaxhighlight lang="ecmascript">import "/math" for Int
import "/trait" for Stepped
import "/trait" for Stepped
import "/fmt" for Fmt
import "/fmt" for Fmt
Line 2,666: Line 2,666:
strangePrimes.call(29, false)
strangePrimes.call(29, false)
var c = strangePrimes.call(999, true)
var c = strangePrimes.call(999, true)
Fmt.print("\nThere are $,d unique prime triples under 1,000 which sum to a prime.", c)</lang>
Fmt.print("\nThere are $,d unique prime triples under 1,000 which sum to a prime.", c)</syntaxhighlight>


{{out}}
{{out}}
Line 2,719: Line 2,719:
===Faster===
===Faster===
The following version uses a prime sieve and is about 17 times faster than the 'basic' version.
The following version uses a prime sieve and is about 17 times faster than the 'basic' version.
<lang ecmascript>import "/math" for Int
<syntaxhighlight lang="ecmascript">import "/math" for Int
import "/fmt" for Fmt
import "/fmt" for Fmt


Line 2,749: Line 2,749:
strangePrimes.call(29, false)
strangePrimes.call(29, false)
var c = strangePrimes.call(999, true)
var c = strangePrimes.call(999, true)
Fmt.print("\nThere are $,d unique prime triples under 1,000 which sum to a prime.", c)</lang>
Fmt.print("\nThere are $,d unique prime triples under 1,000 which sum to a prime.", c)</syntaxhighlight>


{{out}}
{{out}}
Line 2,755: Line 2,755:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>func IsPrime(N); \Return 'true' if N is prime
<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,788: Line 2,788:
];
];
];
];
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}