Ormiston triples: Difference between revisions

Content added Content deleted
(Add Python)
(→‎{{header|Go}}: Doh, what a silly mistake!)
Line 114: Line 114:
</pre>
</pre>
=={{header|Go}}==
=={{header|Go}}==
{{incorrect|Go|this is the Wren code}}
{{trans|Wren}}
{{trans|Wren}}
{{libheader|Go-rcu}}
{{libheader|Go-rcu}}
This runs in about 54 seconds on my Core i7 machine.
This runs in about 54 seconds on my Core i7 machine.
<syntaxhighlight lang="go">import "./math" for Int
<syntaxhighlight lang="go">package main
import "./fmt" for Fmt


import (
var limit = 1e10
"fmt"
var primes = Int.segmentedSieve(limit, 8)
"rcu"
var orm25 = []
)
var j = 1e9

var count = 0
func main() {
var counts = []
const limit = 1e10
for (i in 0...primes.count-2) {
var p1 = primes[i]
primes := rcu.Primes(limit)
var p2 = primes[i+1]
var orm25 []int
var p3 = primes[i+2]
j := int(1e9)
count := 0
if ((p2 - p1) % 18 != 0 || (p3 - p2) % 18 != 0) continue
var key1 = 1
var counts []int
for (dig in Int.digits(p1)) key1 = key1 * primes[dig]
for i := 0; i < len(primes)-2; i++ {
var key2 = 1
p1 := primes[i]
for (dig in Int.digits(p2)) key2 = key2 * primes[dig]
p2 := primes[i+1]
if (key1 != key2) continue
p3 := primes[i+2]
if (p2-p1)%18 != 0 || (p3-p2)%18 != 0 {
var key3 = 1
for (dig in Int.digits(p3)) key3 = key3 * primes[dig]
continue
if (key2 == key3) {
if (count < 25) orm25.add(p1)
if (p1 >= j) {
counts.add(count)
j = j * 10
}
}
count = count + 1
key1 := 1
for _, dig := range rcu.Digits(p1, 10) {
key1 *= primes[dig]
}
key2 := 1
for _, dig := range rcu.Digits(p2, 10) {
key2 *= primes[dig]
}
if key1 != key2 {
continue
}
key3 := 1
for _, dig := range rcu.Digits(p3, 10) {
key3 *= primes[dig]
}
if key2 == key3 {
if count < 25 {
orm25 = append(orm25, p1)
}
if p1 >= j {
counts = append(counts, count)
j *= 10
}
count++
}
}
counts = append(counts, count)
fmt.Println("Smallest members of first 25 Ormiston triples:")
for i := 0; i < 25; i++ {
fmt.Printf("%8v ", orm25[i])
if (i+1)%5 == 0 {
fmt.Println()
}
}
fmt.Println()
j = int(1e9)
for i := 0; i < len(counts); i++ {
fmt.Printf("%s Ormiston triples before %s\n", rcu.Commatize(counts[i]), rcu.Commatize(j))
j *= 10
fmt.Println()
}
}
}
counts.add(count)
System.print("Smallest members of first 25 Ormiston triples:")
Fmt.tprint("$,10d ", orm25, 5)
System.print()
j = 1e9
for (i in 0...counts.count) {
Fmt.print("$,d Ormiston triples before $,d", counts[i], j)
j = j * 10
System.print()
}</syntaxhighlight>
}</syntaxhighlight>