Penta-power prime seeds: Difference between revisions
no edit summary
Thundergnat (talk | contribs) m (Remove draft tag. Draft for over a year, multiple implementations, little controversy) |
No edit summary |
||
Line 504:
82655 126489 207285 211091 234359 256719 366675 407945 414099 628859
644399 770531 781109 782781 923405 1121189 1158975 1483691 1490475 1512321</syntaxhighlight>
=={{header|Julia}}==
This solution uses Primes to determine primality.
<syntaxhighlight lang=julia>
using Primes, Printf
function ispenta(n)
all(0:4) do i
isprime(n^i + n + 1)
end
end
function firstpenta(m, T=BigInt)
nums = Iterators.countfrom(T(1))
pentas = Iterators.filter(ispenta, nums)
firstn = Iterators.take(pentas, m)
return collect(firstn)
end
function table_display(nums, num_columns)
num_elements = length(nums)
num_rows = div(num_elements, num_columns)
remaining_elements = num_elements % num_columns
for i in 1:num_rows
for j in 1:num_columns
index = (i - 1) * num_columns + j
print(nums[index], "\t")
end
println()
end
for i in 1:remaining_elements
index = num_rows * num_columns + i
print(nums[index], "\t")
end
println()
end
function stretch_penta(goal, T=BigInt)
nums = Iterators.countfrom(T(1))
pentas = Iterators.filter(ispenta, nums)
firstn = Iterators.takewhile(<=(goal), pentas)
return collect(firstn)
end
function run_rosetta()
fp = firstpenta(30)
println("First 30 Penta power prime seeds:")
table_display(fp, 10)
sp = stretch_penta(20000000)
milestones = 1000000 .* (1:10)
for milestone in milestones
index = findfirst(>(milestone), sp)
@printf "First element over %9i: %9i, index:%4i\n" milestone sp[index] index
end
end
if abspath(PROGRAM_FILE) == @__FILE__
run_rosetta()
end
</syntaxhighlight>
<pre>
First 30 Penta power prime seeds:
1 5 69 1665 2129 25739 29631 62321 77685 80535
82655 126489 207285 211091 234359 256719 366675 407945 414099 628859
644399 770531 781109 782781 923405 1121189 1158975 1483691 1490475 1512321
First element over 1000000: 1121189, index: 26
First element over 2000000: 2066079, index: 39
First element over 3000000: 3127011, index: 47
First element over 4000000: 4059525, index: 51
First element over 5000000: 5279175, index: 59
First element over 6000000: 6320601, index: 63
First element over 7000000: 7291361, index: 68
First element over 8000000: 8334915, index: 69
First element over 9000000: 9100671, index: 71
First element over 10000000: 10347035, index: 72
</pre>
=={{header|jq}}==
|