Compare commits

...

3 Commits

Author SHA1 Message Date
Nico 9e937d19df more part 2 changes, still unfinished 2020-12-10 15:31:49 +00:00
Nico d8bc9fbe2c incomplete part 2 2020-12-10 15:18:50 +00:00
Nico 895f9ce065 day 10 part 1 2020-12-10 14:39:07 +00:00
3 changed files with 154 additions and 0 deletions

98
day10/input Normal file
View File

@ -0,0 +1,98 @@
35
111
135
32
150
5
106
154
41
7
27
117
109
63
64
21
138
98
40
71
144
13
66
48
12
55
119
103
54
78
65
112
39
128
53
140
77
34
28
81
151
125
85
124
2
99
131
59
60
6
94
33
42
93
14
141
92
38
104
9
29
100
52
19
147
49
74
70
84
113
120
91
97
17
45
139
90
116
149
129
87
69
20
24
148
18
58
123
76
118
130
132
75
110
105
1
8
86

47
day10/main.go Normal file
View File

@ -0,0 +1,47 @@
package main
import (
"fmt"
"sort"
"math"
"strconv"
"strings"
"io/ioutil"
)
func main() {
d, _ := ioutil.ReadFile("input")
strings := strings.Split(string(d),"\n")
ints := []int{0} // start with the connector
for _, s := range strings {
i, err := strconv.Atoi(s)
if err == nil {
ints = append(ints, i)
}
}
sort.Ints(ints)
counts := make(map[int]int)
ints = append(ints, ints[len(ints)-1]+3) // add the phone
// Part 1: Find the number of 1-gaps and 3-gaps
prev := 0
var gaps []int
for _, c := range ints[1:] {
d := c - prev
prev = c
counts[d] += 1
gaps = append(gaps, d)
}
fmt.Println("Part 1:", counts[1] * counts[3])
// Part 2: Find number of skippable adapters
skippable := 0
for i, _ := range ints {
if !(i == 0 || i+1 == len(ints)) { // The first and last cannot be removed
if ints[i+1] - ints[i-1] <= 3 {
skippable += 1
}
}
}
fmt.Println(gaps)
fmt.Printf("Part 2: %f\n", math.Pow(2, float64(skippable))-1) // All possible combinations for n, according to wikipedia
}

9
day10/notes Normal file
View File

@ -0,0 +1,9 @@
if the one before and the one after an adapter can connect, that adapter can be dropped
find all these possible drops
number of possible combinations of these drops
https://en.wikipedia.org/wiki/Binomial_coefficient maybe?
https://en.wikipedia.org/wiki/Combination "Number of k-combinations for all k"
(2^n)-1
Applying this blindly doesn't work because some combinations are invalid (multiple adapters next to each other cannot all be removed, because that leads to greater than 3 overall). I don't want to have to check every possible combination, that would be slow.
Some adapters can only be skipped in the case others are not. Could I check for these and count them as one?
3s cannot be changed. Runs of 1s can be changed.