Prime triangle: Difference between revisions
m
optimize a bit more
m (optimized slightly) |
m (optimize a bit more) |
||
Line 46:
function primetriangle(nrows::Integer)
nrows < 2 && error("number of rows requested must be > 1")
pmask, spinlock = primesmask(2 * (nrows + 1)), Threads.SpinLock()
counts, rowstrings = [1; zeros(Int, nrows - 1)], ["" for _ in 1:nrows]
@Threads.threads for e in collect(permutations(2:2:r))
p[i += 1] =
if
rowstrings[r] = " 1" * prod([lpad(n, 3) for n in p]) * lpad(r + 1, 3) * "\n"
end
counts[r] += 1
unlock(spinlock)
end
▲ counts[r] += 1
end
end
Line 89 ⟶ 93:
[1, 1, 1, 1, 1, 2, 4, 7, 24, 80, 216, 648, 1304, 3392, 13808, 59448]
</pre>
|