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"
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. */
 
see? "working..." + nl
 
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, n = 12)
add(Primes,nextPrime)
for n = oldPrime1 =to nextPrimesqrt(limit)
nextPrime = oldPrime + pow(n, deg)
else
nextPrime =if isprime(nextPrime - oldPrime)
ok 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
? 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
diffs = Primes[n+1]string(x) -l Primes[n]= 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
2 83 3 1811 1 1728 12
3 1811 7 2027 4 216 6
7 2027 11 2243 4 216 6
11 2243 47 2251 36 8 2
47 2251 83 2467 36 216 6
83 2467 227 2531 144 64 4
227 2531 263 2539 36 8 2
263 2539 587 3539 3241000 10
587 3539 911 3547 324 8 2
911 3547 947 4547 361000 10
947 4547 983 5059 36 512 8
983 5059 101910891 5832 36 18
1019 10891 12619 1163 1728 144 12
1163 12619 13619 1307 1000 144 10
1307 13619 13627 1451 144 8 2
1451 13627 13691 1487 3664 4
1487 13691 13907 1523 216 36 6
1523 13907 14419 1559 512 36 8
Found 23 primes under 15000 for cubic gaps.
1559 2459 900
 
2459 3359 900
quartic:
3359 4259 900
4259 prime1 prime2 4583Gap 324Rt
4583 54832 900 3 1 1
5483 55193 36 19 16 2
Found 3 primes under 30000 for quartic gaps.
5519 5843 324
 
5843 5879 36
quintic:
5879 6203 324
6203 prime1 prime2 6779Gap 576Rt
6779 71032 324 3 1 1
7103 72473 32771 144 32768 8
7247 32771 32803 7283 3632 2
7283 32803 33827 7607 1024 324 4
7607 33827 41603 7643 7776 36 6
Found 6 primes under 50000 for quintic gaps.
7643 8219 576
 
8219 8363 144
sextic:
8363 10667 2304
10667 prime1 prime2 11243Gap 576Rt
11243 112792 36 3 1 1
11279 114233 144 67 64 2
11423 67 12323 900131 64 2
Found 4 primes under 50000 for sextic gaps.
12323 12647 324
 
12647 12791 144
septic:
12791 13367 576
13367 prime1 prime2 13691Gap 324Rt
13691 145912 900 3 1 1
14591 146273 36 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}}==