CalmoSoft primes: Difference between revisions

Content added Content deleted
m (→‎{{header|FreeBASIC}}: corrected output, 8 ==> 89)
Line 875: Line 875:
function calmo_prime_sequence(N)
function calmo_prime_sequence(N)
pri = primes(N)
pri = primes(N)
for window_size in lastindex(pri):-1:2
for w in lastindex(pri):-1:2
for i in firstindex(pri):lastindex(pri)-window_size
psum = sum(pri[1:w])
if isprime(sum(pri[i:i+window_size]))
for d in 0:lastindex(pri)-w
if d > 0
println("Longest Calmo prime seq (length ", window_size + 1,
") of primes less than $N totals ", sum(pri[i:i+window_size]))
psum -= pri[d]
if window_size > 24
psum += pri[w + d]
println(string(pri[i:i+5])[begin:end-1], ", ... ",
end
if isprime(psum)
string(pri[i-5+window_size:i+window_size])[begin+1:end], "\n")
println("Longest Calmo prime seq (length ", w,
") of primes less than $N totals ", sum(pri[begin+d:d+w]))
if w > 24
println(string(pri[d+1:d+6])[begin:end-1], ", ... ",
string(pri[d-5+w:d+w])[begin+1:end], "\n")
else
else
println("The sequence is: ", pri[i:i+window_size], "\n")
println("The sequence is: ", pri[d+1:d+w], "\n")
end
end
return
return
Line 892: Line 897:
end
end


foreach(calmo_prime_sequence, [100, 500_000, 50_000_000])
calmo_prime_sequence(100)
calmo_prime_sequence(50_000_000)
</syntaxhighlight>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>

Longest Calmo prime seq (length 21) of primes less than 100 totals 953
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]
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 41530) of primes less than 500000 totals 9910236647
[2, 3, 5, 7, 11, 13, ... 499787, 499801, 499819, 499853, 499879, 499883]


Longest Calmo prime seq (length 3001117) of primes less than 50000000 totals 72618848632313
Longest Calmo prime seq (length 3001117) of primes less than 50000000 totals 72618848632313