day 10 part 1

This commit is contained in:
Nico 2020-12-10 14:39:07 +00:00
parent a3a27299b6
commit 895f9ce065
2 changed files with 129 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

31
day10/main.go Normal file
View File

@ -0,0 +1,31 @@
package main
import (
"fmt"
"sort"
"strconv"
"strings"
"io/ioutil"
)
func main() {
d, _ := ioutil.ReadFile("input")
strings := strings.Split(string(d),"\n")
var ints []int
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
prev := 0
for _, c := range ints {
d := c - prev
prev = c
counts[d] += 1
}
fmt.Println("Part 1:", counts[1] * counts[3]) // add the final one
}