Ormiston pairs: Difference between revisions
Content added Content deleted
(J) |
(Added Go) |
||
Line 142: | Line 142: | ||
382 Ormiston pairs less than a million. |
382 Ormiston pairs less than a million. |
||
</pre> |
|||
=={{header|Go}}== |
|||
{{trans|Wren}} |
|||
{{libheader|Go-rcu}} |
|||
<syntaxhighlight lang="go">package main |
|||
import ( |
|||
"fmt" |
|||
"rcu" |
|||
"sort" |
|||
) |
|||
func areEqual(l1, l2 []int) bool { |
|||
len1 := len(l1) |
|||
len2 := len(l2) |
|||
if len1 != len2 { |
|||
return false |
|||
} |
|||
for i := 0; i < len1; i++ { |
|||
if l1[i] != l2[i] { |
|||
return false |
|||
} |
|||
} |
|||
return true |
|||
} |
|||
func main() { |
|||
const limit = 1e7 |
|||
primes := rcu.Primes(limit) |
|||
var orm30 [][2]int |
|||
i := 0 |
|||
j := int(1e5) |
|||
count := 0 |
|||
var counts []int |
|||
for i < len(primes)-1 { |
|||
p1 := primes[i] |
|||
p2 := primes[i+1] |
|||
if (p2-p1)%18 != 0 { |
|||
i++ |
|||
continue |
|||
} |
|||
d1 := rcu.Digits(p1, 10) |
|||
d2 := rcu.Digits(p2, 10) |
|||
sort.Ints(d1) |
|||
sort.Ints(d2) |
|||
if areEqual(d1, d2) { |
|||
if count < 30 { |
|||
orm30 = append(orm30, [2]int{p1, p2}) |
|||
} |
|||
if p1 >= j { |
|||
counts = append(counts, count) |
|||
j *= 10 |
|||
} |
|||
count++ |
|||
i += 2 |
|||
} else { |
|||
i++ |
|||
} |
|||
} |
|||
counts = append(counts, count) |
|||
fmt.Println("First 30 Ormiston pairs:") |
|||
for i := 0; i < 30; i++ { |
|||
fmt.Printf("%5v ", orm30[i]) |
|||
if (i+1)%3 == 0 { |
|||
fmt.Println() |
|||
} |
|||
} |
|||
fmt.Printf("\n%d Ormiston pairs before 100,000\n", counts[0]) |
|||
fmt.Printf("%d Ormiston pairs before 1,000,000\n", counts[1]) |
|||
fmt.Printf("%s Ormiston pairs before 10,000,000\n", rcu.Commatize(counts[2])) |
|||
}</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
First 30 Ormiston pairs: |
|||
[ 1913 1931] [18379 18397] [19013 19031] |
|||
[25013 25031] [34613 34631] [35617 35671] |
|||
[35879 35897] [36979 36997] [37379 37397] |
|||
[37813 37831] [40013 40031] [40213 40231] |
|||
[40639 40693] [45613 45631] [48091 48109] |
|||
[49279 49297] [51613 51631] [55313 55331] |
|||
[56179 56197] [56713 56731] [58613 58631] |
|||
[63079 63097] [63179 63197] [64091 64109] |
|||
[65479 65497] [66413 66431] [74779 74797] |
|||
[75913 75931] [76213 76231] [76579 76597] |
|||
40 Ormiston pairs before 100,000 |
|||
382 Ormiston pairs before 1,000,000 |
|||
3,722 Ormiston pairs before 10,000,000 |
|||
</pre> |
</pre> |
||