-
Notifications
You must be signed in to change notification settings - Fork 0
/
9.go
59 lines (48 loc) · 813 Bytes
/
9.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
package main
import "fmt"
func main9() {
input := getXmas()
notValid := 0
for i, num := range input {
if i < 25 {
continue
}
found := false
for _, preamble := range input[i-25 : i] {
for _, preamble2 := range input[i-25 : i] {
if preamble+preamble2 == num {
found = true
goto afterLoop
}
}
}
afterLoop:
if found == false {
notValid = num
break
}
}
fmt.Println("part 1:", notValid)
for i := range input {
iTemp := i
result := 0
for result != notValid && iTemp < len(input)-1 {
result += input[iTemp]
iTemp++
}
if result == notValid {
min := notValid
max := 0
for _, x := range input[i:iTemp] {
if x > max {
max = x
}
if x < min {
min = x
}
}
fmt.Println("part 2:", min+max)
break
}
}
}