Primes whose first and last number is 3: Difference between revisions

Content added Content deleted
(Realize in F#)
Line 203: Line 203:
Found 2,251 primes under 1,000,000 which begin and end with 3.
Found 2,251 primes under 1,000,000 which begin and end with 3.
</pre>
</pre>

=={{header|Nim}}==
<lang Nim>import strformat

func isPrime(n: Positive): bool =
for d in countup(3, n, 2):
if d * d > n: break
if n mod d == 0: return false
result = true


iterator primes3x3(lim: Natural): int =
assert lim >= 3
yield 3
var m = 100
while m * 3 < lim:
for n in countup(3 * m + 3, 4 * m - 7, 10):
if n > lim: break
if n.isPrime: yield n
m *= 10

var list: seq[int]
var count = 0
for n in primes3x3(1_000_000):
inc count
if n < 4000: list.add n

echo &"Found {list.len} primes starting and ending with 3 below 4_000:"
for i, n in list:
stdout.write &"{n:4}", if (i + 1) mod 11 == 0: '\n' else: ' '

echo &"\nFound {count} primes starting and ending with 3 below 1_000_000."</lang>

{{out}}
<pre>Found 33 primes starting and ending with 3 below 4_000:
3 313 353 373 383 3023 3083 3163 3203 3253 3313
3323 3343 3373 3413 3433 3463 3533 3583 3593 3613 3623
3643 3673 3733 3793 3803 3823 3833 3853 3863 3923 3943

Found 2251 primes starting and ending with 3 below 1_000_000.</pre>


=={{header|Perl}}==
=={{header|Perl}}==