Cousin primes: Difference between revisions

Content added Content deleted
(Added 11l)
Line 18: Line 18:
:*   the MathWorld entry:   [https://mathworld.wolfram.com/CousinPrimes.html cousin primes].
:*   the MathWorld entry:   [https://mathworld.wolfram.com/CousinPrimes.html cousin primes].
<br><br>
<br><br>

=={{header|11l}}==
{{trans|Nim}}

<lang 11l>V LIMIT = 1000

F isPrime(n)
I (n [&] 1) == 0
R n == 2
V m = 3
L m * m <= n
I n % m == 0
R 0B
m += 2
R 1B

V PrimeList = (2 .< LIMIT).filter(n -> isPrime(n))

V PrimeSet = Set(PrimeList)

V cousinList = PrimeList.filter(n -> (n + 4) C PrimeSet).map(n -> (n, n + 4))

print(‘Found #. cousin primes less than #.:’.format(cousinList.len, LIMIT))
L(cousins) cousinList
print(String(cousins).center(10), end' I (L.index + 1) % 7 == 0 {"\n"} E ‘ ’)
print()</lang>

{{out}}
<pre>
Found 41 cousin primes less than 1000:
(3, 7) (7, 11) (13, 17) (19, 23) (37, 41) (43, 47) (67, 71)
(79, 83) (97, 101) (103, 107) (109, 113) (127, 131) (163, 167) (193, 197)
(223, 227) (229, 233) (277, 281) (307, 311) (313, 317) (349, 353) (379, 383)
(397, 401) (439, 443) (457, 461) (463, 467) (487, 491) (499, 503) (613, 617)
(643, 647) (673, 677) (739, 743) (757, 761) (769, 773) (823, 827) (853, 857)
(859, 863) (877, 881) (883, 887) (907, 911) (937, 941) (967, 971)
</pre>


=={{header|Ada}}==
=={{header|Ada}}==