Jump to content

Cubic special primes: Difference between revisions

m
syntax highlighting fixup automation
(Added XPL0 example.)
m (syntax highlighting fixup automation)
Line 10:
{{trans|FreeBASIC}}
 
<langsyntaxhighlight lang="11l">F is_prime(a)
I a == 2
R 1B
Line 30:
print(p, end' ‘ ’)
E
n++</langsyntaxhighlight>
 
{{out}}
Line 39:
=={{header|Action!}}==
{{libheader|Action! Sieve of Eratosthenes}}
<langsyntaxhighlight Actionlang="action!">INCLUDE "H6:SIEVE.ACT"
 
PROC Main()
Line 62:
OD
PrintF("%E%EThere are %I cubic special primes",count)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Cubic_Special_Primes.png Screenshot from Atari 8-bit computer]
Line 73:
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<langsyntaxhighlight lang="algol68">BEGIN # find a sequence of primes where the members differ by a cube #
INT max prime = 15 000;
# sieve the primes to max prime #
Line 94:
OD;
print( ( newline ) )
END</langsyntaxhighlight>
{{out}}
<pre>
Line 101:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin % find a sequence of primes where the members differ by a cube %
integer MAX_PRIME, MAX_CUBE;
MAX_PRIME := 15000;
Line 135:
end;
write()
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 142:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f CUBIC_SPECIAL_PRIMES.AWK
# converted from FreeBASIC
Line 175:
return(1)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 185:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// Cubic Special Primes: Nigel Galloway. March 30th., 2021
let fN=let N=[for n in [0..25]->n*n*n] in let mutable n=2 in (fun g->match List.contains(g-n)N with true->n<-g; true |_->false)
primes32()|>Seq.takeWhile((>)16000)|>Seq.filter fN|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 197:
=={{header|Factor}}==
{{works with|Factor|0.98}}
<langsyntaxhighlight lang="factor">USING: fry io kernel lists lists.lazy math math.functions
math.primes prettyprint ;
 
2 [ 1 lfrom swap '[ 3 ^ _ + ] lmap-lazy [ prime? ] lfilter car ]
lfrom-by [ 15000 < ] lwhile [ pprint bl ] leach nl</langsyntaxhighlight>
{{out}}
<pre>
Line 208:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">
#include once "isprime.bas"
 
Line 225:
loop until p + n^3 >= 15000
print
end</langsyntaxhighlight>
{{out}}<pre>
2 3 11 19 83 1811 2027 2243 2251 2467 2531 2539 3539 3547 4547 5059 10891 12619 13619 13627 13691 13907 14419
Line 232:
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 306:
}
fmt.Println("\n", count+1, "such primes found.")
}</langsyntaxhighlight>
 
{{out}}
Line 318:
'''Works with gojq, the Go implementation of jq'''
 
For the definition of `is_prime` used here, see https://rosettacode.org/wiki/Additive_primes<langsyntaxhighlight lang="jq"># Output: an array
def cubic_special_primes:
. as $N
Line 339:
15000
| ("Cubic special primes < \(.):",
cubic_special_primes)</langsyntaxhighlight>
{{out}}
<pre>
Line 346:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Primes
 
function cubicspecialprimes(N = 15000)
Line 366:
println("Cubic special primes < 15000:")
foreach(p -> print(rpad(p[2], 6), p[1] % 10 == 0 ? "\n" : ""), enumerate(cubicspecialprimes()))
</langsyntaxhighlight>{{out}}
<pre>
Cubic special primes < 16000:
Line 375:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">start = {2};
Do[
If[PrimeQ[i],
Line 386:
{i, 3, 15000}
]
start</langsyntaxhighlight>
{{out}}
<pre>{2,3,11,19,83,1811,2027,2243,2251,2467,2531,2539,3539,3547,4547,5059,10891,12619,13619,13627,13691,13907,14419}</pre>
Line 392:
=={{header|Nim}}==
{{trans|Go}}
<langsyntaxhighlight Nimlang="nim">import math, strformat
 
func sieve(limit: Positive): seq[bool] =
Line 428:
lastCubicSpecial = n
inc count
echo &"\n{count + 1} such primes found."</langsyntaxhighlight>
 
{{out}}
Line 460:
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 473:
} until $sp[-1] >= 15000;
 
pop @sp and say join ' ', @sp;</langsyntaxhighlight>
{{out}}
<pre>2 3 11 19 83 1811 2027 2243 2251 2467 2531 2539 3539 3547 4547 5059 10891 12619 13619 13627 13691 13907 14419</pre>
Line 482:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">#!/usr/bin/python
 
def isPrime(n):
Line 503:
n += 1
if p + n**3 >= 15000:
break</langsyntaxhighlight>
{{out}}
<pre>2 3 11 19 83 1811 2027 2243 2251 2467 2531 2539 3539 3547 4547 5059 10891 12619 13619 13627 13691 13907 14419</pre>
Line 510:
=={{header|Raku}}==
A two character difference from the [[Quadrat_Special_Primes#Raku|Quadrat Special Primes]] entry. (And it could have been one.)
<syntaxhighlight lang="raku" perl6line>my @sqp = 2, -> $previous {
my $next;
for (1..∞).map: *³ {
Line 520:
 
say "{+$_} matching numbers:\n", $_».fmt('%5d').batch(7).join: "\n" given
@sqp[^(@sqp.first: * > 15000, :k)];</langsyntaxhighlight>
{{out}}
<pre>23 matching numbers:
Line 529:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program finds the smallest primes such that the difference of successive terms */
/*───────────────────────────────────────────────────── are the smallest cubic numbers. */
parse arg hi cols . /*obtain optional argument from the CL.*/
Line 579:
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; s.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 594:
=={{header|Ring}}==
Also see [[Quadrat_Special_Primes#Ring]]
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 630:
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 662:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func cubic_primes(callback) {
 
var prev = 2
Line 679:
take(k)
})
}</langsyntaxhighlight>
{{out}}
<pre>
Line 688:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "/math" for Int
import "/fmt" for Fmt
 
Line 706:
}
}
System.print("\n%(count+1) such primes found.")</langsyntaxhighlight>
 
{{out}}
Line 739:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
Line 763:
];
until N > 15000;
]</langsyntaxhighlight>
 
{{out}}
10,343

edits

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