Cubic special primes: Difference between revisions

Added Wren
(→‎{{header|Raku}}: Add a Raku example)
(Added Wren)
Line 86:
Found 23 of the smallest primes < 15,000 such that the difference of successive terma are the smallest cubic numbers
done...
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Int, Math
import "/fmt" for Fmt
 
var isCube = Fn.new { |n|
var c = Math.cbrt(n).round
return c*c*c == n
}
 
var primes = Int.primeSieve(14999)
System.print("Cubic special primes under 15,000:")
System.print(" Prime1 Prime2 Gap Cbrt")
var lastCubicSpecial = 3
var gap = 1
var count = 1
Fmt.print("$,7d $,7d $,6d $4d", 2, 3, 1, 1)
for (p in primes.skip(2)) {
gap = p - lastCubicSpecial
if (isCube.call(gap)) {
Fmt.print("$,7d $,7d $,6d $4d", lastCubicSpecial, p, gap, Math.cbrt(gap).round)
lastCubicSpecial = p
count = count + 1
}
}
System.print("\n%(count+1) such primes found.")</lang>
 
{{out}}
<pre>
Cubic special primes under 15,000:
Prime1 Prime2 Gap Cbrt
2 3 1 1
3 11 8 2
11 19 8 2
19 83 64 4
83 1,811 1,728 12
1,811 2,027 216 6
2,027 2,243 216 6
2,243 2,251 8 2
2,251 2,467 216 6
2,467 2,531 64 4
2,531 2,539 8 2
2,539 3,539 1,000 10
3,539 3,547 8 2
3,547 4,547 1,000 10
4,547 5,059 512 8
5,059 10,891 5,832 18
10,891 12,619 1,728 12
12,619 13,619 1,000 10
13,619 13,627 8 2
13,627 13,691 64 4
13,691 13,907 216 6
13,907 14,419 512 8
 
23 such primes found.
</pre>
9,482

edits