CalmoSoft primes: Difference between revisions
→{{header|Go}}: Updated in line with Wren entry of which it is a translation.
(Removed Algol 68 stretch - it got the answer wrong ... : {) |
(→{{header|Go}}: Updated in line with Wren entry of which it is a translation.) |
||
Line 273:
"fmt"
"rcu"
"
)
var start = time.Now()
func main() {▼
primes := rcu.Primes(100)▼
const max = 50_000_000
pc := len(primes)▼
func calmoPrimes(limit int) (int, []int, []int, []int) {
var pc, sum int
if limit < max {
break
}▼
} else {
}
for i := 0; i < pc; i++ {
}
longest := 0
var sIndices, eIndices, sums []int
for i := 0; i < pc; i++ {
break
}
if i > 0 {
}
sum2 := sum
for j := pc - 1; j >= i; j-- {
temp := j - i + 1
Line 287 ⟶ 312:
break
}
}
if rcu.IsPrime(sum2) {
if temp > longest {
longest = temp
sIndices = []int{i}
eIndices = []int{j}
sums = []int{sum2}
} else {
sIndices = append(sIndices, i)
eIndices = append(eIndices, j)
sums = append(sums, sum2)
}
break
Line 301 ⟶ 330:
}
}
return longest, sIndices, eIndices, sums
fmt.Println("The longest sequence(s) of CalmoSoft primes having a length of", longest, "is/are:\n")▼
}
▲ for i := 0; i < len(sIndices); i++ {
cp := primes[sIndices[i] : eIndices[i]+1]▼
▲func main() {
▲ sum := rcu.SumInts(cp)
for _, limit := range []int{100, 250, 5000, 10000, 500000, 50000000} {
▲ cps := ""
fmt.Println("For primes up to", rcu.Commatize(limit), "the longest sequence(s) of CalmoSoft primes")
▲ cps += strconv.Itoa(cp[i])
▲ fmt.Println("
▲ if i < len(cp)-1 {
for i := 0; i < len(sIndices);
cp2 := primes[eIndices[i]-5 : eIndices[i]+1]
cps := ""
for _, p := range cp1 {
cps += fmt.Sprintf("%d + ", p)
}
cps += ".. + "
for _, p := range cp2 {
cps += fmt.Sprintf("%d + ", p)
}
fmt.Printf("%s = %s\n", cps[:len(cps)-3], rcu.Commatize(sums[i]))
}
▲ fmt.Println(cps)
▲ if i < len(sIndices)-1 {
▲ fmt.Println()
▲ }
}
fmt.Printf("Took %d ms\n", time.Since(start).Milliseconds())
}</syntaxhighlight>
{{out}}
<pre>
having a length of 21 is/are:
7 + 11 + 13 + 17 + 19 + 23 +
For primes up to 250 the longest sequence(s) of CalmoSoft primes
having a length of 49 is/are:
11 + 13 + 17 + 19 + 23 + 29 + .. + 223 + 227 + 229 + 233 + 239 + 241 = 5,813
For primes up to 5,000 the longest sequence(s) of CalmoSoft primes
having a length of 665 is/are:
7 + 11 + 13 + 17 + 19 + 23 + .. + 4957 + 4967 + 4969 + 4973 + 4987 + 4993 = 1,543,127
For primes up to 10,000 the longest sequence(s) of CalmoSoft primes
having a length of 1,223 is/are:
3 + 5 + 7 + 11 + 13 + 17 + .. + 9883 + 9887 + 9901 + 9907 + 9923 + 9929 = 5,686,633
7 + 11 + 13 + 17 + 19 + 23 + .. + 9901 + 9907 + 9923 + 9929 + 9931 + 9941 = 5,706,497
For primes up to 500,000 the longest sequence(s) of CalmoSoft primes
having a length of 41,530 is/are:
2 + 3 + 5 + 7 + 11 + 13 + .. + 499787 + 499801 + 499819 + 499853 + 499879 + 499883 = 9,910,236,647
For primes up to 50,000,000 the longest sequence(s) of CalmoSoft primes
having a length of 3,001,117 is/are:
7 + 11 + 13 + 17 + 19 + 23 + .. + 49999699 + 49999711 + 49999739 + 49999751 + 49999753 + 49999757 = 72,618,848,632,313
Took 270 ms
▲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>
|