Day 10 possibly complete

but way to resource intensive
This commit is contained in:
Brian Buller 2020-12-10 09:31:02 -06:00
parent 655fafd37f
commit 9f412dbd29
5 changed files with 296 additions and 0 deletions

97
2020/day10/input Normal file
View File

@ -0,0 +1,97 @@
8
131
91
35
47
116
105
121
56
62
94
72
13
82
156
102
12
59
31
138
46
120
7
127
126
111
2
123
22
69
18
157
75
149
88
81
23
98
132
1
63
142
37
133
61
112
122
128
155
145
139
66
42
134
24
60
9
28
17
29
101
148
96
68
25
19
6
67
113
55
40
135
97
79
48
159
14
43
86
36
41
85
87
119
30
108
80
152
158
151
32
78
150
95
3
52
49

117
2020/day10/main.go Normal file
View File

@ -0,0 +1,117 @@
package main
import (
"fmt"
"sort"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
fmt.Println("# Day 10")
inp := h.StdinToIntSlice()
sort.Ints(inp)
jumps := part1(inp)
fmt.Println("## Part 1")
fmt.Println(jumps[1] * jumps[3])
fmt.Println("## Part 2")
fmt.Println(part2(inp))
}
func part1(inp []int) map[int]int {
jumps := make(map[int]int)
var curr int
var used []int
wrk := make([]int, len(inp))
copy(wrk, inp)
for len(used) < len(inp) {
var next int
for i := range wrk {
if i == 0 {
next = wrk[i]
} else {
diff := wrk[i] - curr
if diff > 0 && diff < next-curr {
next = wrk[i]
}
}
}
jumps[next-curr]++
curr = next
used = append(used, curr)
var nextList []int
for i := range wrk {
if wrk[i] != curr {
nextList = append(nextList, wrk[i])
}
}
wrk = make([]int, len(nextList))
copy(wrk, nextList)
}
jumps[3]++
return jumps
}
var prevs map[int][]int
var psbs map[int][][]int
func part2(inp []int) int {
psbs = make(map[int][][]int)
psbs[0] = [][]int{{0}}
prevs = make(map[int][]int)
var phone int
for i := range inp {
if inp[i] > phone {
phone = inp[i]
}
}
// Add the outlet
inp = append(inp, 0)
// Add the phone
phone = phone + 3
inp = append(inp, phone)
for i := range inp {
prevs[inp[i]] = findPrevPoss(inp[i], inp)
}
total := len(findConfigs(phone))
return total
}
func findConfigs(curr int) [][]int {
if p, ok := psbs[curr]; ok {
return p
} else {
var ret [][]int
for _, v := range prevs[curr] {
rec := findConfigs(v)
if len(rec) > 0 {
for _, rv := range rec {
ret = append(ret, append([]int{curr}, rv...))
}
} else {
ret = [][]int{{curr}}
}
}
psbs[curr] = ret
return ret
}
}
// Find the options immediately preceeding curr
func findPrevPoss(curr int, inp []int) []int {
if curr == 0 {
return []int{}
}
var next []int
for i := range inp {
if inp[i] >= curr {
continue
}
if curr-inp[i] <= 3 {
next = append(next, inp[i])
}
}
return next
}

40
2020/day10/out Normal file
View File

@ -0,0 +1,40 @@
# Day 10
## Part 1
35
## Part 2
22 Finding configs
22 Digging
19 Finding configs
19 Digging
16 Finding configs
16 Digging
15 Finding configs
15 Digging
12 Finding configs
12 Digging
10 Finding configs
10 Digging
7 Finding configs
7 Digging
4 Finding configs
4 Digging
1 Finding configs
1 Digging
0 Finding configs
0 Already known []
5 Finding configs
5 Digging
4 Finding configs
4 Already known [[4 1]]
6 Finding configs
6 Digging
4 Finding configs
4 Already known [[4 1]]
5 Finding configs
5 Already known [[5 4 1]]
11 Finding configs
11 Digging
10 Finding configs
10 Already known [[10 7 4 1] [10 7 5 4 1] [10 7 6 4 1] [10 7 6 5 4 1]]
map[0:[] 1:[[1]] 4:[[4 1]] 5:[[5 4 1]] 6:[[6 4 1] [6 5 4 1]] 7:[[7 4 1] [7 5 4 1] [7 6 4 1] [7 6 5 4 1]] 10:[[10 7 4 1] [10 7 5 4 1] [10 7 6 4 1] [10 7 6 5 4 1]] 11:[[11 10 7 4 1] [11 10 7 5 4 1] [11 10 7 6 4 1] [11 10 7 6 5 4 1]] 12:[[12 10 7 4 1] [12 10 7 5 4 1] [12 10 7 6 4 1] [12 10 7 6 5 4 1] [12 11 10 7 4 1] [12 11 10 7 5 4 1] [12 11 10 7 6 4 1] [12 11 10 7 6 5 4 1]] 15:[[15 12 10 7 4 1] [15 12 10 7 5 4 1] [15 12 10 7 6 4 1] [15 12 10 7 6 5 4 1] [15 12 11 10 7 4 1] [15 12 11 10 7 5 4 1] [15 12 11 10 7 6 4 1] [15 12 11 10 7 6 5 4 1]] 16:[[16 15 12 10 7 4 1] [16 15 12 10 7 5 4 1] [16 15 12 10 7 6 4 1] [16 15 12 10 7 6 5 4 1] [16 15 12 11 10 7 4 1] [16 15 12 11 10 7 5 4 1] [16 15 12 11 10 7 6 4 1] [16 15 12 11 10 7 6 5 4 1]] 19:[[19 16 15 12 10 7 4 1] [19 16 15 12 10 7 5 4 1] [19 16 15 12 10 7 6 4 1] [19 16 15 12 10 7 6 5 4 1] [19 16 15 12 11 10 7 4 1] [19 16 15 12 11 10 7 5 4 1] [19 16 15 12 11 10 7 6 4 1] [19 16 15 12 11 10 7 6 5 4 1]] 22:[[22 19 16 15 12 10 7 4 1] [22 19 16 15 12 10 7 5 4 1] [22 19 16 15 12 10 7 6 4 1] [22 19 16 15 12 10 7 6 5 4 1] [22 19 16 15 12 11 10 7 4 1] [22 19 16 15 12 11 10 7 5 4 1] [22 19 16 15 12 11 10 7 6 4 1] [22 19 16 15 12 11 10 7 6 5 4 1]]]
8

11
2020/day10/testinput Normal file
View File

@ -0,0 +1,11 @@
16
10
15
5
1
11
7
19
6
12
4

31
2020/day10/testinput2 Normal file
View File

@ -0,0 +1,31 @@
28
33
18
42
31
14
46
20
48
47
24
23
49
45
19
38
39
11
1
32
25
35
8
17
7
9
4
2
34
10
3