Honaker primes: Difference between revisions
→{{header|Python}}: Updated
(Added Quackery.) |
(→{{header|Python}}: Updated) |
||
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:
<syntaxhighlight lang="python">'''Honaker primes'''
from itertools import
from functools import reduce
# honakers :: [Int]
def honakers():
'''Infinite stream of Honaker terms,
tupled with their 1-based indices.
'''
def
return
) else []▼
return
)
Line 523 ⟶ 522:
0
)
# ------------------------- TEST -------------------------
# main :: IO ()
def main():
'''First 50 Honaker primes, and ten thousandth.'''
'''Test'''▼
print ("First 50 (prime index, Honaker) pairs:
for xs in (▼
str(n) for n
)▼
print(" ".join(repr(x) for x in xs))▼
print("\n10Kth:\n")
Line 577 ⟶ 571:
else:
seen[
until
lambda x: x
▲ )
] = p
# table :: Int -> [String] -> String
def table(n):
'''A list of strings formatted as
right-justified rows of n columns.
def go(xs):
w = len(max(xs, key=len))
' '.join(row) for row in chunksOf(n)([
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.
'''
while not
▲ v = f(v)
▲ return v
▲ return g
▲ return go
# MAIN ---
if __name__ == '__main__':
main()
</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)
|