Check if sum of first n primes is prime: Difference between revisions
Content added Content deleted
m (→{{header|Julia}}: list n) |
|||
Line 14: | Line 14: | ||
So, with a bit of experimentation, we find that to duplicate the Ring result we need to sum up to the first 160 primes, which then |
So, with a bit of experimentation, we find that to duplicate the Ring result we need to sum up to the first 160 primes, which then |
||
gives us 20 prime results when we filter for a prime number as the sum: |
gives us 20 prime results when we filter for a prime number as the sum: |
||
<lang julia>julia> filter(isprime, accumulate(+, primes(prime(160)))) |
<lang julia>julia> julia> filter(p -> isprime(p[2]), collect(enumerate(accumulate(+, primes(prime(160)))))) |
||
20-element Vector{Int64}: |
20-element Vector{Tuple{Int64, Int64}}: |
||
(1, 2) |
|||
(2, 5) |
|||
(4, 17) |
|||
(6, 41) |
|||
(12, 197) |
|||
(14, 281) |
|||
(60, 7699) |
|||
(64, 8893) |
|||
22039 |
(96, 22039) |
||
24133 |
(100, 24133) |
||
25237 |
(102, 25237) |
||
28697 |
(108, 28697) |
||
32353 |
(114, 32353) |
||
37561 |
(122, 37561) |
||
38921 |
(124, 38921) |
||
43201 |
(130, 43201) |
||
44683 |
(132, 44683) |
||
55837 |
(146, 55837) |
||
61027 |
(152, 61027) |
||
66463 |
(158, 66463) |
||
</lang> |
</lang> |
||
=={{header|Ring}}== |
=={{header|Ring}}== |