Smarandache prime-digital sequence: Difference between revisions

(Added 11l)
Line 1,113:
<pre>1-25 : 2 3 5 7 23 37 53 73 223 227 233 257 277 337 353 373 523 557 577 727 733 757 773 2237 2273
100th: 33223</pre>
 
=={{header|Nim}}==
<lang Nim>import math, strformat, strutils
 
const N = 35_000
 
# Sieve.
var composite: array[0..N, bool] # Default is false and means prime.
composite[0] = true
composite[1] = true
for n in 2..sqrt(N.toFloat).int:
if not composite[n]:
for k in countup(n * n, N, n):
composite[k] = true
 
 
func digits(n: Positive): seq[0..9] =
var n = n.int
while n != 0:
result.add n mod 10
n = n div 10
 
 
proc isSPDS(n: int): bool =
if composite[n]: return false
result = true
for d in n.digits:
if composite[d]: return false
 
 
iterator spds(maxCount: Positive): int {.closure.} =
yield 2
var count = 1
var n = 3
while count != maxCount and n <= N:
if n.isSPDS:
inc count
yield n
inc n, 2
if count != maxCount:
quit &"Too few values ({count}). Please, increase value of N.", QuitFailure
 
 
stdout.write "The first 25 SPDS are:"
for n in spds(25):
stdout.write ' ', n
echo()
 
var count = 0
for n in spds(100):
inc count
if count == 100:
echo "The 100th SPDS is: ", n</lang>
 
{{out}}
<pre>The first 25 SPDS are: 2 3 5 7 23 37 53 73 223 227 233 257 277 337 353 373 523 557 577 727 733 757 773 2237 2273
The 100th SPDS is: 33223</pre>
 
=={{header|Pascal}}==
Anonymous user