Jump to content

Ormiston triples: Difference between revisions

→‎{{header|Go}}: Doh, what a silly mistake!
(Add Python)
(→‎{{header|Go}}: Doh, what a silly mistake!)
Line 114:
</pre>
=={{header|Go}}==
{{incorrect|Go|this is the Wren code}}
{{trans|Wren}}
{{libheader|Go-rcu}}
This runs in about 54 seconds on my Core i7 machine.
<syntaxhighlight lang="go">importpackage "./math" for Intmain
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 = []
var const limit = 1e10
for (i in 0...primes.count-2) {
var p1primes := primes[i]rcu.Primes(limit)
var p2orm25 = primes[i+1]int
var p3j := primes[i+2]int(1e9)
var count := 0
if ((p2 - p1) % 18 != 0 || (p3 - p2) % 18 != 0) continue
var key1counts = 1[]int
for (digi in:= Int.digits(p1))0; key1i =< key1len(primes)-2; *i++ primes[dig]{
var key2 p1 := 1primes[i]
for (dig in Int.digits( p2)) key2 := key2 * primes[digi+1]
if (key1 != key2) continuep3 := primes[i+2]
if ((p2 - p1) % 18 != 0 || (p3 - p2) % 18 != 0) continue{
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
}
countkey1 := count + 1
for _, dig := range rcu.Digits(p1, 10) {
key1 *= primes[dig]
j = j * 10}
key2 := 1
for _, dig := range rcu.Digits(p2, 10) {
key2 *= primes[dig]
}
if key1 != key2 {
continue
}
var key3 := 1
for _, dig := range rcu.Digits(p3, 10) {
key3 *= primes[dig]
}
if (key2 == key3) {
if (count < 25) orm25.add(p1){
orm25 = append(orm25, p1)
}
if (p1 >= j) {
counts = append(counts, count)
j = j *= 10
}
counts.add(count)++
}
}
counts = append(counts, count)
System fmt.printPrintln("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()
var j = int(1e9)
for i := 0; i < len(counts); i++ {
Fmt fmt.printPrintf("$,d%s Ormiston triples before $,d%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>
 
9,485

edits

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