-
Notifications
You must be signed in to change notification settings - Fork 0
/
p104.go
60 lines (49 loc) · 891 Bytes
/
p104.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
56
57
58
59
60
package main
import (
"fmt"
"math/big"
"time"
)
func IsPandigital(x string) bool {
check := make([]bool, 10)
for i := 0; i < 10; i++ {
check[i] = true
}
for _, w := range x {
if check[int(w-'0')] {
check[int(w-'0')] = false
} else {
return false
}
}
return check[0]
}
func main() {
start := time.Now()
fn_1 := big.NewInt(1)
fn_2 := big.NewInt(1)
fn_3 := big.NewInt(1)
k := 2
for {
k++
fn_3.Set(fn_2)
fn_3.Add(fn_3, fn_1)
numStr := fn_3.String()
if len(numStr) > 8 {
if IsPandigital(numStr[:9]) {
fmt.Println("front", k)
}
if IsPandigital(numStr[len(numStr)-9:]) {
fmt.Println("tail", k)
}
if IsPandigital(numStr[:9]) && IsPandigital(numStr[len(numStr)-9:]) {
fmt.Println("front and tail", k)
break
}
}
fn_1.Set(fn_2)
fn_2.Set(fn_3)
}
elapsed := time.Since(start)
fmt.Println("Elasped:", elapsed)
}