Calmo numbers: Difference between revisions

Added Go
m (→‎{{header|Raku}}: Add a Raku example)
(Added Go)
Line 77:
<pre>
165 273 385 399 561 595 665 715 957
</pre>
 
=={{header|Go}}==
{{libheader|Go-rcu}}
<syntaxhighlight lang="go">package main
 
import (
"fmt"
"rcu"
"strconv"
"strings"
)
 
func main() {
const limit = 1000
fmt.Println("Calmo numbers under 1,000:\n")
fmt.Println("Number Eligible divisors Partial sums")
fmt.Println("-------------------------------------------")
for i := 2; i < limit; i++ {
ed := rcu.ProperDivisors(i)[1:]
l := len(ed)
if l == 0 || l%3 != 0 {
continue
}
isCalmo := true
var ps []int
for j := 0; j < l; j += 3 {
sum := ed[j] + ed[j+1] + ed[j+2]
if !rcu.IsPrime(sum) {
isCalmo = false
break
}
ps = append(ps, sum)
}
if isCalmo {
eds := make([]string, len(ed))
for k, e := range ed {
eds[k] = strconv.Itoa(e)
}
seds := "[" + strings.Join(eds, " ") + "]"
fmt.Printf("%3d %-21s %v\n", i, seds, ps)
}
}
}</syntaxhighlight>
 
{{out}}
<pre>
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,477

edits