Unprimeable numbers: Difference between revisions

m (Added Delphi reference to Pascal code)
Line 1,075:
8 is: 208
9 is: 212,159</pre>
 
=={{header|Nim}}==
<lang Nim>import strutils
 
const N = 10_000_000
 
# Erastosthenes sieve.
var composite: array[0..N, bool] # Defualt is false i.e. composite.
composite[0] = true
composite[1] = true
for n in 2..N:
if not composite[n]:
for k in countup(n * n, N, n):
composite[k] = true
 
template isPrime(n: int): bool = not composite[n]
 
 
proc isUmprimeable(n: Positive): bool =
if n.isPrime: return false
var nd = $n
for i, prevDigit in nd:
for newDigit in '0'..'9':
if newDigit != prevDigit:
nd[i] = newDigit
if nd.parseInt.isPrime: return false
nd[i] = prevDigit # Restore initial digit.
result = true
 
 
echo "First 35 unprimeable numbers:"
var n = 100
var list: seq[int]
while list.len < 35:
if n.isUmprimeable:
list.add n
inc n
echo list.join(" "), '\n'
 
var count = 0
n = 199
while count != 600:
inc n
if n.isUmprimeable: inc count
echo "600th unprimeable number: ", ($n).insertSep(','), '\n'
 
for d in 0..9:
var n = 200 + d
while not n.isUmprimeable:
inc n, 10
echo "Lowest unprimeable number ending in ", d, " is ", ($n).insertSep(',')</lang>
 
{{out}}
<pre>First 35 unprimeable numbers:
200 204 206 208 320 322 324 325 326 328 510 512 514 515 516 518 530 532 534 535 536 538 620 622 624 625 626 628 840 842 844 845 846 848 890
 
600th unprimeable number: 5,242
 
Lowest unprimeable number ending in 0 is 200
Lowest unprimeable number ending in 1 is 595,631
Lowest unprimeable number ending in 2 is 322
Lowest unprimeable number ending in 3 is 1,203,623
Lowest unprimeable number ending in 4 is 204
Lowest unprimeable number ending in 5 is 325
Lowest unprimeable number ending in 6 is 206
Lowest unprimeable number ending in 7 is 872,897
Lowest unprimeable number ending in 8 is 208
Lowest unprimeable number ending in 9 is 212,159</pre>
 
=={{header|Pascal}}==
Anonymous user