Erdős–Woods numbers: Difference between revisions
→{{header|Julia}}: threading
(→{{header|Wren}}: Tidied but no quicker.) |
(→{{header|Julia}}: threading) |
||
Line 33:
=={{header|Julia}}==
{{trans|Python}}
<lang julia>""" modified from https://codegolf.stackexchange.com/questions/230509/find-the-erd%C5%91s-woods-origin/ """
<lang julia>""" Returns the smallest value for `a` of the Erdős-Woods number n, or -1 if n is not in the sequence """▼
using BitIntegers
"""
▲
"""
function erdős_woods(n)
primes = Int[]
P =
k = 1
while k < n
Line 43 ⟶ 49:
k += 1
end
divs = [evalpoly(
np = length(primes)
partitions = [(
ort(x) = trailing_zeros(divs[x + 1] | divs[n - x + 1])
for i in sort(collect(1:n-1), lt = (b, c) -> ort(b) > ort(c))
new_partitions = Tuple{
factors = divs[i + 1]
other_factors = divs[n - i + 1]
Line 57 ⟶ 63:
continue
end
for (ix, v) in enumerate(
if v == '1'
w = Int256(1) << (ix - 1)
push!(new_partitions, (set_a ⊻ w, set_b, r_primes ⊻ w))
end
end
for (ix, v) in enumerate(
if v == '1'
w = Int256(1) << (ix - 1)
push!(new_partitions, (set_a, set_b ⊻ w, r_primes ⊻ w))
end
Line 72 ⟶ 78:
partitions = new_partitions
end
result =
for (px, py, _) in partitions
x, y =
for p in primes
isodd(px) && (x *= p)
Line 81 ⟶ 87:
py ÷= 2
end
newresult = ((n * invmod(x, y)) % y) * x - n
result = result == -1 ? newresult : min(result, newresult)
end
Line 87 ⟶ 93:
end
function test_erdős_woods(startval=3, endval=116)
arr = fill((0, Int256(-1)), endval - startval + 1)
@Threads.threads for k in startval:endval
println("The first 20 Erdős–Woods numbers and their minimum interval start values are:")▼
end
▲ a = erdős_woods(k)
ewvalues = filter(x ->
▲ println("The first
for (k, a) in
end
end
|