-
Notifications
You must be signed in to change notification settings - Fork 0
/
p61.go
119 lines (106 loc) · 1.81 KB
/
p61.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"fmt"
"time"
)
func Trail(sets [][]int, check []bool, head, tail, left int) int {
for i, used := range check {
if !used {
for _, v := range sets[i] {
if v/100 == tail {
if left > 1 {
check[i] = true
curr := Trail(sets, check, head, v%100, left-1)
check[i] = false
if curr > 0 {
return curr + v
}
} else {
if v%100 == head {
return v
}
}
}
}
}
}
return 0
}
func main() {
start := time.Now()
check := make([]bool, 6)
sets := make([][]int, 6)
for i := 0; i < 6; i++ {
sets[i] = []int{}
}
for n := 10; ; n++ {
curr := n * (n + 1) / 2
if curr > 999 {
if curr > 9999 {
break
} else if curr%100 > 9 {
sets[0] = append(sets[0], curr)
}
}
}
for n := 10; ; n++ {
curr := n * n
if curr > 999 {
if curr > 9999 {
break
} else if curr%100 > 9 {
sets[1] = append(sets[1], curr)
}
}
}
for n := 10; ; n++ {
curr := n * (3*n - 1) / 2
if curr > 999 {
if curr > 9999 {
break
} else if curr%100 > 9 {
sets[2] = append(sets[2], curr)
}
}
}
for n := 10; ; n++ {
curr := n * (2*n - 1)
if curr > 999 {
if curr > 9999 {
break
} else if curr%100 > 9 {
sets[3] = append(sets[3], curr)
}
}
}
for n := 10; ; n++ {
curr := n * (5*n - 3) / 2
if curr > 999 {
if curr > 9999 {
break
} else if curr%100 > 9 {
sets[4] = append(sets[4], curr)
}
}
}
for n := 10; ; n++ {
curr := n * (3*n - 2)
if curr > 999 {
if curr > 9999 {
break
} else if curr%100 > 9 {
sets[5] = append(sets[5], curr)
}
}
}
check[0] = true
for _, v := range sets[0] {
curr := Trail(sets, check, v/100, v%100, 5)
if curr > 0 {
fmt.Println(curr + v)
break
}
}
elapsed := time.Since(start)
fmt.Println("Elasped:", elapsed)
}