Skip to content

Commit d47e06a

Browse files
author
Peter de Kraker
committed
very verbose solution, but it works
1 parent 90536b3 commit d47e06a

File tree

4 files changed

+11952
-0
lines changed

4 files changed

+11952
-0
lines changed

day10_input.txt

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
bot 75 gives low to bot 145 and high to bot 95
2+
bot 116 gives low to bot 157 and high to bot 197
3+
bot 185 gives low to bot 57 and high to bot 139
4+
bot 202 gives low to bot 105 and high to bot 209
5+
bot 179 gives low to output 20 and high to bot 133
6+
bot 114 gives low to bot 140 and high to bot 51
7+
bot 166 gives low to bot 95 and high to bot 87
8+
bot 57 gives low to bot 118 and high to bot 32
9+
bot 33 gives low to bot 141 and high to bot 105
10+
bot 68 gives low to bot 86 and high to bot 25
11+
bot 139 gives low to bot 32 and high to bot 28
12+
bot 18 gives low to bot 186 and high to bot 136
13+
bot 99 gives low to bot 41 and high to bot 83
14+
bot 155 gives low to bot 43 and high to bot 78
15+
bot 157 gives low to bot 55 and high to bot 185
16+
bot 204 gives low to bot 83 and high to bot 54
17+
bot 22 gives low to bot 187 and high to bot 148
18+
bot 48 gives low to bot 151 and high to bot 160
19+
value 7 goes to bot 77
20+
bot 154 gives low to bot 138 and high to bot 4
21+
bot 206 gives low to output 15 and high to bot 203
22+
value 11 goes to bot 113
23+
bot 47 gives low to bot 209 and high to bot 86
24+
bot 187 gives low to bot 54 and high to bot 37
25+
bot 103 gives low to output 13 and high to bot 125
26+
bot 92 gives low to bot 150 and high to bot 131
27+
bot 102 gives low to bot 56 and high to bot 164
28+
bot 37 gives low to bot 44 and high to bot 11
29+
bot 80 gives low to bot 17 and high to bot 84
30+
bot 52 gives low to bot 143 and high to bot 38
31+
bot 168 gives low to bot 170 and high to bot 2
32+
bot 188 gives low to bot 161 and high to bot 180
33+
bot 17 gives low to bot 93 and high to bot 109
34+
bot 117 gives low to bot 81 and high to bot 168
35+
bot 25 gives low to bot 59 and high to bot 71
36+
bot 173 gives low to bot 192 and high to bot 126
37+
bot 118 gives low to output 7 and high to bot 96
38+
bot 1 gives low to bot 155 and high to bot 100
39+
bot 64 gives low to bot 125 and high to bot 192
40+
bot 5 gives low to bot 197 and high to bot 8
41+
bot 136 gives low to bot 202 and high to bot 47
42+
bot 59 gives low to bot 7 and high to bot 130
43+
bot 197 gives low to bot 185 and high to bot 0
44+
bot 94 gives low to bot 16 and high to bot 39
45+
bot 138 gives low to bot 87 and high to bot 65
46+
bot 20 gives low to bot 128 and high to bot 208
47+
value 59 goes to bot 162
48+
bot 201 gives low to bot 119 and high to bot 177
49+
bot 32 gives low to bot 96 and high to bot 90
50+
bot 174 gives low to bot 36 and high to bot 124
51+
bot 60 gives low to bot 158 and high to bot 34
52+
value 53 goes to bot 140
53+
bot 141 gives low to bot 152 and high to bot 175
54+
bot 145 gives low to bot 183 and high to bot 146
55+
bot 190 gives low to output 1 and high to bot 36
56+
bot 113 gives low to bot 194 and high to bot 157
57+
value 41 goes to bot 143
58+
bot 61 gives low to bot 171 and high to bot 144
59+
bot 8 gives low to bot 0 and high to bot 152
60+
bot 170 gives low to bot 193 and high to bot 91
61+
bot 65 gives low to bot 147 and high to bot 93
62+
bot 6 gives low to bot 205 and high to bot 182
63+
bot 45 gives low to bot 195 and high to bot 13
64+
bot 98 gives low to bot 111 and high to bot 46
65+
bot 172 gives low to bot 154 and high to bot 7
66+
bot 119 gives low to bot 131 and high to bot 169
67+
bot 199 gives low to bot 117 and high to bot 156
68+
bot 128 gives low to bot 179 and high to bot 208
69+
bot 84 gives low to bot 109 and high to bot 21
70+
bot 86 gives low to bot 172 and high to bot 59
71+
value 43 goes to bot 104
72+
bot 165 gives low to bot 27 and high to bot 72
73+
bot 62 gives low to bot 58 and high to bot 120
74+
bot 109 gives low to bot 121 and high to bot 102
75+
bot 115 gives low to bot 24 and high to bot 151
76+
bot 19 gives low to bot 52 and high to bot 76
77+
bot 125 gives low to output 2 and high to bot 107
78+
bot 76 gives low to bot 38 and high to bot 155
79+
value 61 goes to bot 52
80+
bot 14 gives low to bot 153 and high to bot 53
81+
bot 180 gives low to bot 106 and high to bot 15
82+
bot 30 gives low to bot 28 and high to bot 75
83+
bot 121 gives low to bot 60 and high to bot 56
84+
bot 200 gives low to output 16 and high to bot 206
85+
bot 163 gives low to bot 71 and high to bot 14
86+
bot 146 gives low to bot 174 and high to bot 16
87+
bot 12 gives low to bot 11 and high to bot 10
88+
bot 127 gives low to bot 126 and high to bot 129
89+
bot 101 gives low to bot 64 and high to bot 173
90+
bot 7 gives low to bot 4 and high to bot 80
91+
bot 189 gives low to bot 51 and high to bot 62
92+
bot 85 gives low to bot 98 and high to bot 108
93+
bot 169 gives low to bot 204 and high to bot 187
94+
bot 160 gives low to bot 123 and high to bot 112
95+
bot 40 gives low to bot 182 and high to bot 70
96+
bot 158 gives low to bot 101 and high to bot 178
97+
bot 175 gives low to bot 159 and high to bot 67
98+
bot 183 gives low to bot 190 and high to bot 174
99+
bot 95 gives low to bot 146 and high to bot 94
100+
bot 110 gives low to bot 115 and high to bot 48
101+
bot 55 gives low to bot 49 and high to bot 57
102+
bot 159 gives low to bot 75 and high to bot 166
103+
bot 208 gives low to bot 133 and high to bot 196
104+
bot 131 gives low to bot 99 and high to bot 204
105+
value 2 goes to bot 19
106+
value 47 goes to bot 24
107+
value 31 goes to bot 194
108+
bot 70 gives low to bot 199 and high to bot 156
109+
bot 120 gives low to bot 112 and high to bot 198
110+
bot 42 gives low to bot 22 and high to bot 191
111+
bot 23 gives low to bot 177 and high to bot 42
112+
bot 144 gives low to bot 23 and high to bot 79
113+
bot 107 gives low to output 9 and high to bot 161
114+
bot 81 gives low to bot 15 and high to bot 170
115+
bot 143 gives low to bot 176 and high to bot 88
116+
bot 186 gives low to bot 33 and high to bot 202
117+
bot 205 gives low to bot 127 and high to bot 50
118+
bot 27 gives low to bot 3 and high to bot 97
119+
bot 87 gives low to bot 94 and high to bot 147
120+
bot 41 gives low to bot 100 and high to bot 18
121+
bot 50 gives low to bot 129 and high to bot 199
122+
bot 66 gives low to output 4 and high to bot 190
123+
bot 171 gives low to bot 201 and high to bot 23
124+
value 37 goes to bot 27
125+
bot 10 gives low to bot 142 and high to bot 163
126+
bot 148 gives low to bot 37 and high to bot 12
127+
bot 195 gives low to bot 165 and high to bot 31
128+
bot 36 gives low to output 6 and high to bot 26
129+
bot 162 gives low to bot 114 and high to bot 189
130+
bot 104 gives low to bot 162 and high to bot 189
131+
bot 82 gives low to bot 67 and high to bot 154
132+
bot 196 gives low to output 17 and high to output 8
133+
bot 39 gives low to bot 85 and high to bot 89
134+
bot 78 gives low to bot 134 and high to bot 33
135+
bot 167 gives low to bot 203 and high to bot 128
136+
bot 44 gives low to bot 73 and high to bot 63
137+
bot 97 gives low to bot 207 and high to bot 132
138+
bot 13 gives low to bot 31 and high to bot 9
139+
bot 46 gives low to bot 103 and high to bot 64
140+
bot 203 gives low to output 14 and high to bot 179
141+
value 23 goes to bot 195
142+
bot 182 gives low to bot 50 and high to bot 70
143+
bot 112 gives low to bot 61 and high to bot 198
144+
bot 184 gives low to bot 89 and high to bot 60
145+
bot 67 gives low to bot 166 and high to bot 138
146+
bot 88 gives low to bot 116 and high to bot 5
147+
bot 31 gives low to bot 72 and high to bot 92
148+
bot 198 gives low to bot 144 and high to bot 79
149+
bot 83 gives low to bot 18 and high to bot 29
150+
bot 0 gives low to bot 139 and high to bot 30
151+
value 19 goes to bot 115
152+
bot 3 gives low to bot 19 and high to bot 207
153+
value 13 goes to bot 114
154+
bot 89 gives low to bot 108 and high to bot 158
155+
bot 176 gives low to bot 113 and high to bot 116
156+
value 5 goes to bot 3
157+
bot 181 gives low to bot 48 and high to bot 58
158+
bot 26 gives low to output 19 and high to bot 111
159+
value 3 goes to bot 45
160+
bot 4 gives low to bot 65 and high to bot 17
161+
bot 11 gives low to bot 63 and high to bot 10
162+
bot 177 gives low to bot 169 and high to bot 22
163+
bot 71 gives low to bot 130 and high to bot 14
164+
bot 108 gives low to bot 46 and high to bot 101
165+
bot 207 gives low to bot 76 and high to bot 1
166+
value 17 goes to bot 104
167+
bot 126 gives low to bot 188 and high to bot 149
168+
bot 135 gives low to bot 164 and high to bot 40
169+
bot 105 gives low to bot 175 and high to bot 82
170+
bot 153 gives low to bot 84 and high to bot 53
171+
bot 35 gives low to bot 122 and high to bot 171
172+
bot 164 gives low to bot 6 and high to bot 40
173+
bot 124 gives low to bot 26 and high to bot 98
174+
bot 69 gives low to bot 13 and high to bot 122
175+
bot 49 gives low to output 0 and high to bot 118
176+
bot 193 gives low to bot 206 and high to bot 167
177+
bot 133 gives low to output 5 and high to bot 196
178+
bot 24 gives low to bot 74 and high to bot 137
179+
bot 111 gives low to output 18 and high to bot 103
180+
bot 192 gives low to bot 107 and high to bot 188
181+
value 29 goes to bot 110
182+
bot 72 gives low to bot 97 and high to bot 150
183+
bot 140 gives low to bot 110 and high to bot 181
184+
bot 191 gives low to bot 148 and high to bot 12
185+
value 67 goes to bot 74
186+
bot 132 gives low to bot 1 and high to bot 41
187+
bot 16 gives low to bot 124 and high to bot 85
188+
bot 156 gives low to bot 168 and high to bot 2
189+
bot 58 gives low to bot 160 and high to bot 120
190+
bot 43 gives low to bot 5 and high to bot 134
191+
bot 77 gives low to output 11 and high to bot 49
192+
bot 21 gives low to bot 102 and high to bot 135
193+
bot 178 gives low to bot 173 and high to bot 127
194+
bot 63 gives low to bot 68 and high to bot 142
195+
bot 194 gives low to bot 77 and high to bot 55
196+
bot 51 gives low to bot 181 and high to bot 62
197+
bot 209 gives low to bot 82 and high to bot 172
198+
bot 38 gives low to bot 88 and high to bot 43
199+
bot 130 gives low to bot 80 and high to bot 153
200+
bot 29 gives low to bot 136 and high to bot 73
201+
bot 56 gives low to bot 34 and high to bot 6
202+
bot 54 gives low to bot 29 and high to bot 44
203+
bot 150 gives low to bot 132 and high to bot 99
204+
bot 106 gives low to output 12 and high to bot 200
205+
bot 79 gives low to bot 42 and high to bot 191
206+
bot 147 gives low to bot 39 and high to bot 184
207+
bot 93 gives low to bot 184 and high to bot 121
208+
bot 90 gives low to bot 66 and high to bot 183
209+
bot 123 gives low to bot 35 and high to bot 61
210+
bot 53 gives low to bot 21 and high to bot 135
211+
bot 137 gives low to bot 69 and high to bot 35
212+
bot 28 gives low to bot 90 and high to bot 145
213+
bot 2 gives low to bot 91 and high to bot 20
214+
bot 91 gives low to bot 167 and high to bot 20
215+
bot 161 gives low to output 3 and high to bot 106
216+
value 71 goes to bot 176
217+
bot 73 gives low to bot 47 and high to bot 68
218+
bot 134 gives low to bot 8 and high to bot 141
219+
bot 9 gives low to bot 92 and high to bot 119
220+
bot 129 gives low to bot 149 and high to bot 117
221+
bot 74 gives low to bot 45 and high to bot 69
222+
bot 34 gives low to bot 178 and high to bot 205
223+
bot 100 gives low to bot 78 and high to bot 186
224+
bot 152 gives low to bot 30 and high to bot 159
225+
bot 149 gives low to bot 180 and high to bot 81
226+
bot 142 gives low to bot 25 and high to bot 163
227+
bot 15 gives low to bot 200 and high to bot 193
228+
bot 96 gives low to output 10 and high to bot 66
229+
value 73 goes to bot 165
230+
bot 151 gives low to bot 137 and high to bot 123
231+
bot 122 gives low to bot 9 and high to bot 201

day10_part1.rb

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
class Robot
2+
3+
attr_accessor :low,:high, :number, :values,:input_receive
4+
5+
def initialize(number)
6+
@number = number
7+
@values = []
8+
@low = nil
9+
@high = nil
10+
end
11+
12+
13+
14+
def can_proceed
15+
@values.length >= 2
16+
end
17+
18+
def proceed
19+
sorted = @values.sort
20+
puts "#{number}: #{@low.number if low } receives #{sorted[0]}, #{@high.number if number} receives #{sorted[1]}"
21+
@low.receive(sorted[0]) if @low
22+
@high.receive(sorted[1]) if @high
23+
@values = []
24+
sorted
25+
end
26+
27+
def receive(value)
28+
puts "#{number} received #{value}"
29+
@values << value
30+
end
31+
32+
def to_s
33+
"bot #{number}: #{@values.inspect} => low: #{@low.number if @low}, high: #{@high.number if @high}"
34+
end
35+
36+
def inspect
37+
to_s
38+
end
39+
40+
end
41+
42+
class Processor
43+
44+
def initialize(commands)
45+
@bots = []
46+
commands.each do |c|
47+
if (c.match(/value (\d+) goes to bot (\d+)/))
48+
puts c
49+
bot($2.to_i).receive($1.to_i)
50+
51+
elsif (c.match(/bot (\d+) gives low to (output|bot) (\d+) and high to (output|bot) (\d+)/))
52+
53+
low_receiver = ($2 == "bot") ? bot($3.to_i): nil
54+
raise c if bot($1.to_i).low != nil
55+
bot($1.to_i).low = low_receiver
56+
57+
high_receiver = ($4 == "bot") ? bot($5.to_i) : nil
58+
raise c if bot($1.to_i).high != nil
59+
bot($1.to_i).high = high_receiver
60+
61+
puts "#{c} => #{bot($1.to_i).number} => low: #{low_receiver.number if low_receiver}, high:#{high_receiver.number if high_receiver}"
62+
else
63+
raise c
64+
65+
end
66+
end
67+
#puts @bots.inspect
68+
end
69+
70+
def process
71+
found = false
72+
round = 0
73+
while (!found)
74+
puts round += 1
75+
@bots.each do |bot|
76+
if (bot.can_proceed)
77+
result = bot.proceed
78+
if ((result & [17,61]).length == 2)
79+
puts "Found answer: #{bot.number}"
80+
found = true
81+
raise "Found"
82+
else
83+
puts result.inspect
84+
end
85+
end
86+
end
87+
88+
end
89+
end
90+
91+
def bot(number)
92+
if (!@bots[number])
93+
@bots[number ] = Robot.new(number)
94+
end
95+
@bots[number]
96+
end
97+
end
98+
99+
test = "value 5 goes to bot 2
100+
bot 2 gives low to bot 1 and high to bot 0
101+
value 3 goes to bot 1
102+
bot 1 gives low to output 1 and high to bot 0
103+
bot 0 gives low to output 2 and high to output 0
104+
value 2 goes to bot 2"
105+
#Processor.new(test.split("\n"))
106+
107+
Processor.new(File.new("day10_input.txt").readlines).process

0 commit comments

Comments
 (0)