Check if sum of first n primes is prime: Difference between revisions
Content added Content deleted
Line 4: | Line 4: | ||
<br><br> |
<br><br> |
||
=={{header|Julia}}== |
|||
<lang julia>using Primes |
|||
</lang> |
|||
The sum of the first 20 primes is |
|||
<lang julia>julia> sum(prime(i) for i in 1:20) |
|||
639 |
|||
</lang> |
|||
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: |
|||
<lang julia>julia> filter(isprime, accumulate(+, primes(prime(160)))) |
|||
20-element Vector{Int64}: |
|||
2 |
|||
5 |
|||
17 |
|||
41 |
|||
197 |
|||
281 |
|||
7699 |
|||
8893 |
|||
22039 |
|||
24133 |
|||
25237 |
|||
28697 |
|||
32353 |
|||
37561 |
|||
38921 |
|||
43201 |
|||
44683 |
|||
55837 |
|||
61027 |
|||
66463 |
|||
</lang> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |