CalmoSoft primes: Difference between revisions

Converted to draft task, clarified and tidied the task description and added a Wren solution.
(Created page with "'''Definition''' <br><br> Let p(1),p(2),p(3), ... ,p(n) be consecutive prime numbers, where p(n) < 100. If the sum of these numbers is a prime number, then these numbers are called '''CalmoSoft primes''' <br><br> '''Task''' <br><br> Let's find and show here the longest sequence of CalmoSoft primes. <br><br> =={{header|Ring}}== <syntaxhighlight lang="ring"> see "works..." + nl limit = 100 Primes = [] OldPrimes = [] NewPrimes = [] for p = 1 to limit if isPrime(p)...")
 
(Converted to draft task, clarified and tidied the task description and added a Wren solution.)
Line 1:
{{draft task}}
''';Definition'''
Let p(1), p(2), p(3), ... , p(n) be consecutive prime numbers, where p(n) < 100. If the sum of any consecutive sub-sequence of these numbers is a prime number, then thesethe numbers in such a sub-sequence are called '''CalmoSoft primes'''.
<br><br>
;Task
Let p(1),p(2),p(3), ... ,p(n) be consecutive prime numbers, where p(n) < 100. If the sum of these numbers is a prime number, then these numbers are called '''CalmoSoft primes'''
Let's findFind and show here the longest sequence of CalmoSoft primes.
<br><br>
'''Task'''
<br><br>
Let's find and show here the longest sequence of CalmoSoft primes.
<br><br>
=={{header|Ring}}==
Line 77 ⟶ 76:
done..
 
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-math}}
<syntaxhighlight lang="ecmascript">import "./math" for Int, Nums
 
var primes = Int.primeSieve(100)
var pc = primes.count
var longest = 0
var sIndices = []
var eIndices = []
for (i in 0...pc) {
for (j in pc-1..i) {
var temp = j - i + 1
if (temp < longest) break
var sum = Nums.sum(primes[i..j])
if (Int.isPrime(sum)) {
if (temp > longest) {
longest = temp
sIndices = [i]
eIndices = [j]
} else {
sIndices.add(i)
eIndices.add(j)
}
break
}
}
}
System.print("The longest sequence(s) of CalmoSoft primes having a length of %(longest) is/are:\n")
for (i in 0...sIndices.count) {
var cp = primes[sIndices[i]..eIndices[i]]
var sum = Nums.sum(cp)
var cps = cp.join(" + ") + " = " + sum.toString + " which is prime"
System.print(cps)
if (i < sIndices.count - 1) System.print()
}</syntaxhighlight>
 
{{out}}
<pre>
The longest sequence(s) of CalmoSoft primes having a length of 21 is/are:
 
7 + 11 + 13 + 17 + 19 + 23 + 29 + 31 + 37 + 41 + 43 + 47 + 53 + 59 + 61 + 67 + 71 + 73 + 79 + 83 + 89 = 953 which is prime
</pre>
9,490

edits