Jump to content

Calmo numbers: Difference between revisions

Added Wren
(Tidied up task description.)
(Added Wren)
Line 192:
Found 9 Calmo numbers
done...
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascript">import "./math" for Int, Nums
import "./seq" for Lst
import "./fmt" for Fmt
 
var limit = 1000
var calmo = []
for (i in 2...limit) {
var ed = Int.properDivisors(i)
ed.removeAt(0)
if (ed.count == 0 || ed.count % 3 != 0) continue
var isCalmo = true
var ps = []
for (chunk in Lst.chunks(ed, 3)) {
var sum = Nums.sum(chunk)
if (!Int.isPrime(sum)) {
isCalmo = false
break
}
ps.add(sum)
}
if (isCalmo) calmo.add([i, ed, ps])
}
System.print("Calmo numbers under 1,000:\n")
System.print("Number Eligible divisors Partial sums")
System.print("----------------------------------------------")
for (e in calmo) {
Fmt.print("$3d $-24n $n", e[0], e[1], e[2])
}</syntaxhighlight>
 
{{out}}
<pre>
Calmo numbers under 1,000:
 
Number Eligible divisors Partial sums
----------------------------------------------
165 [3, 5, 11, 15, 33, 55] [19, 103]
273 [3, 7, 13, 21, 39, 91] [23, 151]
385 [5, 7, 11, 35, 55, 77] [23, 167]
399 [3, 7, 19, 21, 57, 133] [29, 211]
561 [3, 11, 17, 33, 51, 187] [31, 271]
595 [5, 7, 17, 35, 85, 119] [29, 239]
665 [5, 7, 19, 35, 95, 133] [31, 263]
715 [5, 11, 13, 55, 65, 143] [29, 263]
957 [3, 11, 29, 33, 87, 319] [43, 439]
</pre>
9,486

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.