parent
230988d40a
commit
1a8d7eed18
@ -0,0 +1,11 @@
|
||||
16
|
||||
10
|
||||
15
|
||||
5
|
||||
1
|
||||
11
|
||||
7
|
||||
19
|
||||
6
|
||||
12
|
||||
4
|
@ -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
|
@ -0,0 +1,100 @@
|
||||
44
|
||||
41
|
||||
48
|
||||
17
|
||||
35
|
||||
146
|
||||
73
|
||||
3
|
||||
16
|
||||
159
|
||||
11
|
||||
29
|
||||
32
|
||||
63
|
||||
65
|
||||
62
|
||||
126
|
||||
151
|
||||
6
|
||||
124
|
||||
87
|
||||
115
|
||||
122
|
||||
43
|
||||
12
|
||||
85
|
||||
2
|
||||
98
|
||||
59
|
||||
156
|
||||
149
|
||||
66
|
||||
10
|
||||
82
|
||||
26
|
||||
79
|
||||
56
|
||||
22
|
||||
74
|
||||
49
|
||||
25
|
||||
69
|
||||
54
|
||||
19
|
||||
108
|
||||
18
|
||||
55
|
||||
131
|
||||
140
|
||||
15
|
||||
125
|
||||
37
|
||||
129
|
||||
91
|
||||
51
|
||||
158
|
||||
117
|
||||
136
|
||||
142
|
||||
109
|
||||
64
|
||||
36
|
||||
160
|
||||
150
|
||||
42
|
||||
118
|
||||
101
|
||||
78
|
||||
28
|
||||
105
|
||||
110
|
||||
40
|
||||
157
|
||||
70
|
||||
97
|
||||
139
|
||||
152
|
||||
47
|
||||
104
|
||||
81
|
||||
27
|
||||
116
|
||||
132
|
||||
143
|
||||
1
|
||||
80
|
||||
75
|
||||
141
|
||||
133
|
||||
9
|
||||
50
|
||||
153
|
||||
123
|
||||
111
|
||||
119
|
||||
130
|
||||
112
|
||||
94
|
||||
90
|
||||
86
|
@ -0,0 +1,28 @@
|
||||
package day10
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"git.elis.nu/etu/aoc2020/utils"
|
||||
)
|
||||
|
||||
var rows []int
|
||||
|
||||
func ParseFile(input string) {
|
||||
// Add zero as start number
|
||||
rows = append(rows, 0)
|
||||
|
||||
// Parse file
|
||||
for _, line := range utils.GetLinesFromFile("day10/" + input + ".txt") {
|
||||
num, _ := strconv.Atoi(line)
|
||||
|
||||
rows = append(rows, num)
|
||||
}
|
||||
|
||||
// Sort the numbers, will always be needed. And is required for calculation of consolues jolt usage below.
|
||||
sort.Ints(rows)
|
||||
|
||||
// Add the consoles jolt usage by taking the last number plus 3
|
||||
rows = append(rows, rows[len(rows)-1]+3)
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package day10
|
||||
|
||||
import (
|
||||
"log"
|
||||
)
|
||||
|
||||
func Solve1() {
|
||||
count1 := 0
|
||||
count3 := 0
|
||||
|
||||
for key, value := range rows {
|
||||
if key+1 >= len(rows) {
|
||||
break
|
||||
}
|
||||
|
||||
if value+1 == rows[key+1] {
|
||||
count1++
|
||||
}
|
||||
|
||||
if value+3 == rows[key+1] {
|
||||
count3++
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("2020-12-10.01: Answer: %d\n", count1*count3)
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package day10
|
||||
|
||||
import (
|
||||
"log"
|
||||
)
|
||||
|
||||
func Solve2() {
|
||||
log.Printf("2020-12-10.02: Answer: %d\n", calc(rows))
|
||||
}
|
||||
|
||||
func calc(data []int) int {
|
||||
// Some cached answers, these works since we check if they
|
||||
// increment by one when we split up the data below, so if the
|
||||
// chain is a certain length, we know it works.
|
||||
switch len(data) {
|
||||
case 0, 1, 2:
|
||||
return 1
|
||||
case 3:
|
||||
return 2
|
||||
case 4:
|
||||
return 4
|
||||
case 5:
|
||||
return 7
|
||||
}
|
||||
|
||||
// Locate a good place to break the chain in the middle
|
||||
i := 0
|
||||
for i = 0; i < len(data)-1; i++ {
|
||||
if data[i+1] == data[i]+1 {
|
||||
continue
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
if len(data[:i]) >= 0 {
|
||||
return calc(data[:i+1]) * calc(data[i+1:])
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
Loading…
Reference in new issue