Solution for Day 10

This commit is contained in:
Patrick Michl 2020-12-10 09:22:27 +01:00
parent 89090cb0f4
commit 83f4f0b6c6
3 changed files with 133 additions and 0 deletions

17
day_10/first.rb Normal file
View File

@ -0,0 +1,17 @@
# frozen_string_literal: true
input = File.readlines('./input').map(&:to_i).sort
$d = { 1 => 0, 2 => 0, 3 => 0 }
$j = 0
input << input.max + 3
input.each do |adapter|
diff = adapter - $j
if diff.between? 1, 3
$d[diff] += 1
$j = adapter
end
end
puts $d[1] * $d[3]

104
day_10/input Normal file
View File

@ -0,0 +1,104 @@
165
78
151
15
138
97
152
64
4
111
7
90
91
156
73
113
93
135
100
70
119
54
80
170
139
33
123
92
86
57
39
173
22
106
166
142
53
96
158
63
51
81
46
36
126
59
98
2
16
141
120
35
140
99
121
122
58
1
60
47
10
87
103
42
132
17
75
12
29
112
3
145
131
18
153
74
161
174
68
34
21
24
85
164
52
69
65
45
109
148
11
23
129
84
167
27
28
116
110
79
48
32
157
130

12
day_10/second.rb Normal file
View File

@ -0,0 +1,12 @@
# frozen_string_literal: true
input = File.readlines('./input').map(&:to_i).sort
input << input.max + 3
$c = { 0 => 1 }
input.each do |e|
$c[e] = $c.values_at(e - 1, e - 2, e - 3).compact.sum
end
puts $c[input.last]