Quadrat special primes: Difference between revisions
→{{header|Ring}}: cleaned up columns, added additional degrees
(→{{header|Phix}}: added cubic code) |
(→{{header|Ring}}: cleaned up columns, added additional degrees) |
||
Line 366:
=={{header|Ring}}==
<lang ring>load "stdlib.ring"
/* Searching for the smallest prime gaps under a limit,
such that the difference of successive terms (gaps)
is of the smallest degree. */
desc = split("na quadratic cubic quartic quintic sextic septic octic nonic decic"," ")
limits = [1, 16000, 15000, 30000, 50000, 50000, 50000, 75000, 300000, 500000]
for deg = 2 to len(desc)
Primes = []
limit = limits[deg]
oldPrime = 2
add(Primes,
for n =
nextPrime = oldPrime + pow(n, deg)
if nextPrime < limit add(Primes, nextPrime) ok
oldPrime = nextPrime
else
nextPrime = nextPrime - oldPrime
ok
if nextPrime > limit exit ok
next
? nl + desc[deg] + ":" + nl + " prime1 prime2 Gap Rt"
for n = 1 to Len(Primes) - 1
diff = Primes[n + 1] - Primes[n]
? sf(Primes[n], 7) + " " + sf(Primes[n+1], 7) + " " + sf(diff, 6) + " " + sf(floor(0.49 + pow(diff, 1 / deg)), 4)
next
? "Found " + Len(Primes) + " primes under " + limit + " for " + desc[deg] + " gaps."
next
? nl + "done..."
# a very plain string formatter, intended to even up columnar outputs
def sf x, y
if l > y y = l ok
return substr(" ", 11 - y + l) + s</lang>
{{out}}
<pre style="height:20em">working...
quadratic:
prime1 prime2 Gap Rt
2 3 1 1
3 7 4 2
7 11 4 2
11 47 36 6
47 83 36 6
83 227 144 12
227 263 36 6
263 587 324 18
587 911 324 18
911 947 36 6
947 983 36 6
983 1019 36 6
1019 1163 144 12
1163 1307 144 12
1307 1451 144 12
1451 1487 36 6
1487 1523 36 6
1523 1559 36 6
1559 2459 900 30
2459 3359 900 30
3359 4259 900 30
4259 4583 324 18
4583 5483 900 30
5483 5519 36 6
5519 5843 324 18
5843 5879 36 6
5879 6203 324 18
6203 6779 576 24
6779 7103 324 18
7103 7247 144 12
7247 7283 36 6
7283 7607 324 18
7607 7643 36 6
7643 8219 576 24
8219 8363 144 12
8363 10667 2304 48
10667 11243 576 24
11243 11279 36 6
11279 11423 144 12
11423 12323 900 30
12323 12647 324 18
12647 12791 144 12
12791 13367 576 24
13367 13691 324 18
13691 14591 900 30
14591 14627 36 6
14627 14771 144 12
14771 15671 900 30
Found 49 primes under 16000 for quadratic gaps.
cubic:
prime1 prime2 Gap Rt
2 3 1 1
3 11 8 2
11 19 8 2
19 83 64 4
Found 23 primes under 15000 for cubic gaps.
quartic:
Found 3 primes under 30000 for quartic gaps.
quintic:
Found 6 primes under 50000 for quintic gaps.
sextic:
Found 4 primes under 50000 for sextic gaps.
septic:
Found 3 primes under 50000 for septic gaps.
octic:
prime1 prime2 Gap Rt
2 3 1 1
3 65539 65536 4
Found 3 primes under 75000 for octic gaps.
nonic:
prime1 prime2 Gap Rt
2 3 1 1
3 262147 262144 4
Found 3 primes under 300000 for nonic gaps.
decic:
prime1 prime2 Gap Rt
2 3 1 1
Found 2 primes under 500000 for decic gaps.
done...</pre>
=={{header|Wren}}==
|