Honaker primes: Difference between revisions

(Added Quackery.)
Line 492:
The 10,000th Honaker prime is the 286,069th one, which is 4,043,749.</pre>
 
Or, defining an infinite series of Honakers primes, writing our own primes function,
 
and displaying with flexible column widths, for variable sample sizes:
Or, a variant, without importing a primes function:
<syntaxhighlight lang="python">'''Honaker primes'''
 
from itertools import chain, count, islice
from functools import reduce
 
# honakers :: [Int]
 
def honakers():
'''Infinite stream of Honaker terms,
tupled with their 1-based indices.
'''
def fp(ip):
return [digitSum(ip[0]) if== digitSum(ip[1])
digitSum(ip[0]) == digitSum(ip[1])
) else []
 
return chain.from_iterablefilter(
map(fp, zipenumerate(countprimes(1), primes())1)
)
 
Line 523 ⟶ 522:
0
)
 
 
# ------------------------- TEST -------------------------
# main :: IO ()
def main():
'''First 50 Honaker primes, and ten thousandth.'''
'''Test'''
 
print ("First 50 (prime index, Honaker) pairs:\n")
for xs in (
chunksOf(5)print(
listtable(5)([
str(n) for n islice(in
islice(honakers(), 50)
50])
)
)
)
):
print(" ".join(repr(x) for x in xs))
 
print("\n10Kth:\n")
Line 577 ⟶ 571:
else:
seen[
until(lambda x: x not in seen)(
lambda x: x +not 2in * pseen,
)(q lambda x: x + 2 * p),
v = f(v) q + 2 * p
)
] = p
 
 
# table :: Int -> [String] -> String
def table(n):
'''A list of strings formatted as
right-justified rows of n columns.
'''Test'''
def go(xs):
w = len(max(xs, key=len))
return g'\n'.join(
' '.join(row) for row in chunksOf(n)([
print(" " s.joinrjust(repr(xw, ' ') for xs in xs))
) else [ ])
for xs in ( )
return go
 
 
# until :: (a -> Bool) -> (a -> a) -> a -> a
def until(p, f, x):
'''The result of repeatedly applying f until p holds.
The initial seed value is x.
'''
defv go(f):= x
while not def gp(xv):
v = xf(v)
return v
while not p(v):
v = f(v)
return v
return g
return go
 
 
# MAIN ---
if __name__ == '__main__':
main()</syntaxhighlight>
</syntaxhighlight>
{{Out}}
<pre>First 50 (prime index, Honaker) pairs:
(32, 131) (56, 263) (88, 457) (175, 1039) (176, 1049)
 
(32, 131) (56, 263) (88, 457) (175, 1039) (176, 1049)
(182, 1091) (212, 1301) (218, 1361) (227, 1433) (248, 1571)
(293, 1913) (295, 1933) (323, 2141) (331, 2221) (338, 2273)
9,655

edits