-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp52.go
55 lines (45 loc) · 952 Bytes
/
p52.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"strconv"
"time"
)
func main() {
start := time.Now()
x := int64(1)
for {
if len(strconv.FormatInt(x, 10)) == len(strconv.FormatInt(x*6, 10)) {
isSame := true
orgStr := []rune(strconv.FormatInt(x, 10))
for i := 0; i < len(orgStr); i++ {
for j := i + 1; j < len(orgStr); j++ {
if orgStr[i] > orgStr[j] {
orgStr[i], orgStr[j] = orgStr[j], orgStr[i]
}
}
}
for m := 2; isSame && m < 7; m++ {
tmpStr := []rune(strconv.FormatInt(x*int64(m), 10))
for i := 0; i < len(tmpStr); i++ {
for j := i + 1; j < len(tmpStr); j++ {
if tmpStr[i] > tmpStr[j] {
tmpStr[i], tmpStr[j] = tmpStr[j], tmpStr[i]
}
}
}
for i := 0; i < len(orgStr); i++ {
if orgStr[i] != tmpStr[i] {
isSame = false
}
}
}
if isSame {
break
}
}
x++
}
fmt.Println(x)
elapsed := time.Since(start)
fmt.Println("Elasped:", elapsed)
}