CalmoSoft primes: Difference between revisions
m
→{{header|Julia}}
m (→Stretch task) |
|||
Line 580:
=={{header|Julia}}==
<syntaxhighlight lang="julia">using Primes
function calmo_prime_sequence(N
pri = primes(N)
for window_size in lastindex(pri):-1:2
Line 590 ⟶ 589:
println("Longest Calmo prime seq (length ", window_size + 1,
") of primes less than $N totals ", sum(pri[i:i+window_size]))
println(string(pri[1:i+5])[begin:end-1], ", ... ",
string(pri[i-6+window_size:i+window_size])[begin+1:end], "\n")
else
println("The sequence is: ", pri[i:i+window_size], "\n")
end
return
end
Line 597 ⟶ 601:
end
calmo_prime_sequence(100)
calmo_prime_sequence(50_000_000
</syntaxhighlight>{{out}}
<pre>
Longest Calmo prime seq (length 21) of primes less than 100 totals 953
The sequence is: [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89]
Longest Calmo prime seq (length 3001117) of primes less than 50000000 totals 72618848632313
[2, 3, 5, 7, 11, 13, 17, 19, 23, ... 49999693, 49999699, 49999711, 49999739, 49999751, 49999753, 49999757]
</pre>
|