Strange unique prime triplets: Difference between revisions
Content added Content deleted
m (added whitespace to the task's preamble.) |
|||
Line 8: | Line 8: | ||
:* (stretch goal) Show the <u>count</u> (only) of all the triplets of strange unique primes in which '''n, m,''' and '''p''' are all less than '''1,000'''. |
:* (stretch goal) Show the <u>count</u> (only) of all the triplets of strange unique primes in which '''n, m,''' and '''p''' are all less than '''1,000'''. |
||
<br><br> |
<br><br> |
||
=={{header|Phix}}== |
|||
<lang Phix>-- The first 10 primes, ie {2,3,5,7,11,13,17,19,23,29}: |
|||
constant primes = get_primes(-10) |
|||
procedure strange_triplets() |
|||
-- |
|||
-- It is not worth involving 2, ie primes[1], |
|||
-- since (2 + any other two primes) is even, |
|||
-- also we may as well leave space for {j,k}, |
|||
-- {k} in the two outer loops |
|||
-- |
|||
sequence res = {} |
|||
for i=2 to length(primes)-2 do |
|||
integer n = primes[i] |
|||
for j=i+1 to length(primes)-1 do |
|||
integer m = primes[j] |
|||
for k=j+1 to length(primes) do |
|||
integer p = primes[k], |
|||
nmp = n+m+p |
|||
if is_prime(nmp) then |
|||
res = append(res,sprintf("%2d: %2d+%2d+%2d = %d", |
|||
{length(res)+1, n, m, p, nmp})) |
|||
end if |
|||
end for |
|||
end for |
|||
end for |
|||
printf(1,"%d found:\n%s\n",{length(res),join(shorten(res,"",3),"\n")}) |
|||
end procedure |
|||
strange_triplets()</lang> |
|||
{{out}} |
|||
<pre> |
|||
42 found: |
|||
1: 3+ 5+11 = 19 |
|||
2: 3+ 5+23 = 31 |
|||
3: 3+ 5+29 = 37 |
|||
... |
|||
40: 13+19+29 = 61 |
|||
41: 17+19+23 = 59 |
|||
42: 19+23+29 = 71 |
|||
</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |