Super-d numbers: Difference between revisions
Content added Content deleted
(Added Fōrmulæ) |
(→{{header|Go}}: Simplified somewhat, about 10% quicker than before.) |
||
Line 70: | Line 70: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
Simple brute force approach and so not particularly quick - about 2. |
Simple brute force approach and so not particularly quick - about 2.25 minutes on a Core i7. |
||
<lang go>package main |
<lang go>package main |
||
Line 79: | Line 79: | ||
"time" |
"time" |
||
) |
) |
||
func pow(n uint64, exp int) *big.Int { |
|||
b := new(big.Int).SetUint64(n) |
|||
⚫ | |||
⚫ | |||
p.Mul(p, b) |
|||
} |
|||
return p |
|||
} |
|||
func main() { |
func main() { |
||
start := time.Now() |
start := time.Now() |
||
rd := []string{"22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999"} |
rd := []string{"22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999"} |
||
one := big.NewInt(1) |
|||
⚫ | |||
⚫ | |||
fmt.Printf("First 10 super-%d numbers:\n", i) |
fmt.Printf("First 10 super-%d numbers:\n", i) |
||
ii := i.Uint64() |
|||
k := new(big.Int) |
k := new(big.Int) |
||
count := 0 |
count := 0 |
||
inner: |
inner: |
||
for j := |
for j := big.NewInt(3); ; j.Add(j, one) { |
||
k. |
k.Exp(j, i, nil) |
||
k.Mul(i, k) |
|||
ix := strings.Index(k.String(), rd[ii-2]) |
|||
if ix >= 0 { |
if ix >= 0 { |
||
count++ |
count++ |
||
Line 121: | Line 115: | ||
First 10 super-3 numbers: |
First 10 super-3 numbers: |
||
261 462 471 481 558 753 1036 1046 1471 1645 |
261 462 471 481 558 753 1036 1046 1471 1645 |
||
found in |
found in 1 ms |
||
First 10 super-4 numbers: |
First 10 super-4 numbers: |
||
1168 4972 7423 7752 8431 10267 11317 11487 11549 11680 |
1168 4972 7423 7752 8431 10267 11317 11487 11549 11680 |
||
found in |
found in 7 ms |
||
First 10 super-5 numbers: |
First 10 super-5 numbers: |
||
4602 5517 7539 12955 14555 20137 20379 26629 32767 35689 |
4602 5517 7539 12955 14555 20137 20379 26629 32767 35689 |
||
found in |
found in 28 ms |
||
First 10 super-6 numbers: |
First 10 super-6 numbers: |
||
27257 272570 302693 323576 364509 502785 513675 537771 676657 678146 |
27257 272570 302693 323576 364509 502785 513675 537771 676657 678146 |
||
found in |
found in 285 ms |
||
First 10 super-7 numbers: |
First 10 super-7 numbers: |
||
140997 490996 1184321 1259609 1409970 1783166 1886654 1977538 2457756 2714763 |
140997 490996 1184321 1259609 1409970 1783166 1886654 1977538 2457756 2714763 |
||
found in |
found in 1517 ms |
||
First 10 super-8 numbers: |
First 10 super-8 numbers: |
||
185423 641519 1551728 1854230 6415190 12043464 12147605 15517280 16561735 18542300 |
185423 641519 1551728 1854230 6415190 12043464 12147605 15517280 16561735 18542300 |
||
found in |
found in 11117 ms |
||
First 10 super-9 numbers: |
First 10 super-9 numbers: |
||
17546133 32613656 93568867 107225764 109255734 113315082 121251742 175461330 180917907 182557181 |
17546133 32613656 93568867 107225764 109255734 113315082 121251742 175461330 180917907 182557181 |
||
found in |
found in 135616 ms |
||
</pre> |
</pre> |
||