Quadrat special primes: Difference between revisions
Content added Content deleted
(→{{header|Phix}}: added cubic code) |
(→{{header|Ring}}: cleaned up columns, added additional degrees) |
||
Line 366: | Line 366: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
<lang ring> |
<lang ring>load "stdlib.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. */ |
|||
? "working..." |
|||
desc = split("na quadratic cubic quartic quintic sextic septic octic nonic decic"," ") |
|||
Primes = [] |
|||
limits = [1, 16000, 15000, 30000, 50000, 50000, 50000, 75000, 300000, 500000] |
|||
limit1 = 50 |
|||
for deg = 2 to len(desc) |
|||
oldPrime = 1 |
|||
add(Primes,2) |
|||
Primes = [] |
|||
for n = 1 to limit1 |
|||
limit = limits[deg] |
|||
nextPrime = oldPrime + pow(n,2) |
|||
oldPrime = 2 |
|||
if isprime(nextPrime) |
|||
add(Primes, 2) |
|||
add(Primes,nextPrime) |
|||
for n = 1 to sqrt(limit) |
|||
nextPrime = oldPrime + pow(n, deg) |
|||
else |
|||
if isprime(nextPrime) |
|||
n = 1 |
|||
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 |
next |
||
? nl + "done..." |
|||
# a very plain string formatter, intended to even up columnar outputs |
|||
see "prime1 prime2 Gap" + nl |
|||
def sf x, y |
|||
for n = 1 to Len(Primes)-1 |
|||
s = string(x) l = len(s) |
|||
if l > y y = l ok |
|||
see ""+ Primes[n] + " " + Primes[n+1] + " " + diff + nl |
|||
return substr(" ", 11 - y + l) + s</lang> |
|||
next |
|||
{{out}} |
|||
<pre style="height:20em">working... |
|||
quadratic: |
|||
see "Found " + Len(Primes) + " of the smallest primes < 16,000 such that the difference of successive terma are the smallest quadrat numbers" + nl |
|||
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: |
|||
see nl + "done..." + nl |
|||
prime1 prime2 Gap Rt |
|||
</lang> |
|||
2 3 1 1 |
|||
{{out}} |
|||
3 11 8 2 |
|||
<pre> |
|||
11 19 8 2 |
|||
working... |
|||
19 83 64 4 |
|||
prime1 prime2 Gap |
|||
83 1811 1728 12 |
|||
1811 2027 216 6 |
|||
2027 2243 216 6 |
|||
2243 2251 8 2 |
|||
2251 2467 216 6 |
|||
2467 2531 64 4 |
|||
2531 2539 8 2 |
|||
2539 3539 1000 10 |
|||
3539 3547 8 2 |
|||
3547 4547 1000 10 |
|||
4547 5059 512 8 |
|||
5059 10891 5832 18 |
|||
10891 12619 1728 12 |
|||
12619 13619 1000 10 |
|||
13619 13627 8 2 |
|||
13627 13691 64 4 |
|||
13691 13907 216 6 |
|||
13907 14419 512 8 |
|||
Found 23 primes under 15000 for cubic gaps. |
|||
1559 2459 900 |
|||
2459 3359 900 |
|||
quartic: |
|||
3359 4259 900 |
|||
prime1 prime2 Gap Rt |
|||
2 3 1 1 |
|||
3 19 16 2 |
|||
Found 3 primes under 30000 for quartic gaps. |
|||
5519 5843 324 |
|||
5843 5879 36 |
|||
quintic: |
|||
5879 6203 324 |
|||
prime1 prime2 Gap Rt |
|||
2 3 1 1 |
|||
3 32771 32768 8 |
|||
32771 32803 32 2 |
|||
32803 33827 1024 4 |
|||
33827 41603 7776 6 |
|||
Found 6 primes under 50000 for quintic gaps. |
|||
7643 8219 576 |
|||
8219 8363 144 |
|||
sextic: |
|||
8363 10667 2304 |
|||
prime1 prime2 Gap Rt |
|||
2 3 1 1 |
|||
3 67 64 2 |
|||
67 131 64 2 |
|||
Found 4 primes under 50000 for sextic gaps. |
|||
12323 12647 324 |
|||
12647 12791 144 |
|||
septic: |
|||
12791 13367 576 |
|||
prime1 prime2 Gap Rt |
|||
2 3 1 1 |
|||
3 131 128 2 |
|||
Found 3 primes under 50000 for septic gaps. |
|||
14627 14771 144 |
|||
14771 15671 900 |
|||
octic: |
|||
Found 49 of the smallest primes < 16,000 such that the difference of successive terma are the smallest quadrat numbers |
|||
prime1 prime2 Gap Rt |
|||
done... |
|||
2 3 1 1 |
|||
</pre> |
|||
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}}== |
=={{header|Wren}}== |