Sexy primes: Difference between revisions

→‎{{header|Python}}: Add a translation of FSharp
m (→‎{{header|C}}: Removed redundant #include directive.)
(→‎{{header|Python}}: Add a translation of FSharp)
Line 690:
 
=={{header|Python}}==
===Imperative (iffy & loopy) Style===
 
<lang python>LIMIT = 1_000_035
def primes2(limit=LIMIT):
Line 779:
999983
1000003</pre>
===Functional style===
{{trans|FSharp}}
This task uses [[Extensible_prime_generator#210-wheel_postponed_incremental_sieve]]
<lang python>
#Functional Sexy Primes. Nigel Galloway: October 5th., 2018
from itertools import *
z=primes()
n=frozenset(takewhile(lambda x: x<1000035,z))
ni=sorted(list(filter(lambda g: n.__contains__(g+6) ,n)))
print ("There are",len(ni),"sexy prime pairs all components of which are less than 1,000,035. The last 5 are:")
for g in islice(ni,max(len(ni)-5,0),len(ni)): print(format("(%d,%d) " % (g,g+6)))
nig=list(filter(lambda g: n.__contains__(g+12) ,ni))
print ("There are",len(nig),"sexy prime triplets all components of which are less than 1,000,035. The last 5 are:")
for g in islice(nig,max(len(nig)-5,0),len(nig)): print(format("(%d,%d,%d) " % (g,g+6,g+12)))
nige=list(filter(lambda g: n.__contains__(g+18) ,nig))
print ("There are",len(nige),"sexy prime quadruplets all components of which are less than 1,000,035. The last 5 are:")
for g in islice(nige,max(len(nige)-5,0),len(nige)): print(format("(%d,%d,%d,%d) " % (g,g+6,g+12,g+18)))
nigel=list(filter(lambda g: n.__contains__(g+24) ,nige))
print ("There are",len(nigel),"sexy prime quintuplets all components of which are less than 1,000,035. The last 5 are:")
for g in islice(nigel,max(len(nigel)-5,0),len(nigel)): print(format("(%d,%d,%d,%d,%d) " % (g,g+6,g+12,g+18,g+24)))
un=frozenset(takewhile(lambda x: x<1000050,z)).union(n)
unsexy=sorted(list(filter(lambda g: not un.__contains__(g+6) and not un.__contains__(g-6),n)))
print ("There are",len(unsexy),"unsexy primes less than 1,000,035. The last 10 are:")
for g in islice(unsexy,max(len(unsexy)-10,0),len(unsexy)): print(g)
</lang>
{{out}}
<pre>
There are 16386 sexy prime pairs all components of which are less than 1,000,035. The last 5 are:
(999371,999377)
(999431,999437)
(999721,999727)
(999763,999769)
(999953,999959)
There are 2900 sexy prime triplets all components of which are less than 1,000,035. The last 5 are:
(997427,997433,997439)
(997541,997547,997553)
(998071,998077,998083)
(998617,998623,998629)
(998737,998743,998749)
There are 325 sexy prime quadruplets all components of which are less than 1,000,035. The last 5 are:
(977351,977357,977363,977369)
(983771,983777,983783,983789)
(986131,986137,986143,986149)
(990371,990377,990383,990389)
(997091,997097,997103,997109)
There are 1 sexy prime quintuplets all components of which are less than 1,000,035. The last 5 are:
(5,11,17,23,29)
There are 48627 unsexy primes less than 1,000,035. The last 10 are:
999853
999863
999883
999907
999917
999931
999961
999979
999983
1000003
</pre>
 
=={{header|REXX}}==
2,172

edits