Special neighbor primes: Difference between revisions

(Realize in F#)
Line 103:
Found 103,611 special neighbor primes under 10,000,000.
</pre>
 
=={{header|Nim}}==
<lang Nim>import strutils, sugar
 
const Max = 100 - 1
 
func isPrime(n: Positive): bool =
if n == 1: return false
if n mod 2 == 0: return n == 2
for d in countup(3, n, 2):
if d * d > n: break
if n mod d == 0: return false
result = true
 
const Primes = collect(newSeq):
for n in 2..Max:
if n.isPrime: n
 
let list = collect(newSeq):
for i in 0..<Primes.high:
let p1 = Primes[i]
let p2 = Primes[i + 1]
if (p1 + p2 - 1).isPrime: (p1, p2)
 
echo "Found $1 special neighbor primes less than $2:".format(list.len, Max + 1)
echo list.join(", ")</lang>
 
{{out}}
<pre>Found 13 special neighbor primes less than 100:
(3, 5), (5, 7), (7, 11), (11, 13), (13, 17), (19, 23), (29, 31), (31, 37), (41, 43), (43, 47), (61, 67), (67, 71), (73, 79)</pre>
 
=={{header|REXX}}==
Anonymous user