Equal prime and composite sums: Difference between revisions

(→‎{{header|Wren}}: Added a further series term.)
Line 31:
 
 
 
=={{header|Julia}}==
<lang julia>using Primes
 
function getsequencematches(N)
pmask = primesmask(N)
psum, csum, pindex, cindex, pcount, ccount = 2, 4, 2, 4, 1, 1
incrementpsum() = (pindex += 1; if pmask[pindex] psum += pindex; pcount += 1 end)
incrementcsum() = (cindex += 1; if !pmask[cindex] csum += cindex; ccount += 1 end)
while pindex < N
while psum < csum
pindex >= N && @goto done
incrementpsum()
end
if psum == csum
println("Primes up to $pindex at position $pcount and composites up to $cindex at position $ccount sum to $psum.")
while psum == csum
incrementpsum()
incrementcsum()
end
end
while csum < psum
incrementcsum()
end
end
@label done
end
 
getsequencematches(500_000_000)
</lang>{{out}}
<pre>
Primes up to 5 at position 3 and composites up to 6 at position 2 sum to 10.
Primes up to 137 at position 33 and composites up to 72 at position 51 sum to 1988.
Primes up to 409 at position 80 and composites up to 190 at position 147 sum to 14697.
Primes up to 1039 at position 175 and composites up to 448 at position 361 sum to 83292.
Primes up to 4937 at position 660 and composites up to 1868 at position 1582 sum to 1503397.
Primes up to 18787 at position 2143 and composites up to 6544 at position 5699 sum to 18859052.
Primes up to 43753 at position 4556 and composites up to 14522 at position 12821 sum to 93952013.
Primes up to 1565929 at position 118785 and composites up to 440305 at position 403341 sum to 89171409882.
Primes up to 17662763 at position 1131142 and composites up to 4548502 at position 4229425 sum to 9646383703961.
Primes up to 86254457 at position 5012372 and composites up to 21123471 at position 19786181 sum to 209456854921713.
Primes up to 390180569 at position 20840220 and composites up to 91491160 at position 86192660 sum to 3950430820867201.
</pre>
 
=={{header|Phix}}==
4,103

edits