Skip to content

Commit 00c4544

Browse files
committed
(Day 16) Less copy & paste.
1 parent 31b6c6e commit 00c4544

File tree

1 file changed

+13
-66
lines changed

1 file changed

+13
-66
lines changed

day16/day16.adb

Lines changed: 13 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ procedure Day16 is
193193
end Execute;
194194

195195
Opcodes : array (Natural range 0 .. 15) of String_Set_Vectors.Vector;
196-
Opcode_Lookup : array (Natural range 0 .. 15) of Op_String;
196+
Opcode_Lookup : array (Natural range 0 .. 15) of Op_String :=
197+
("addr", "addi", "mulr", "muli", "banr", "bani", "borr", "bori", "setr",
198+
"seti", "gtir", "gtri", "gtrr", "eqir", "eqri", "eqrr");
197199

198200
Part1_Count : Natural := 0;
199201
begin
@@ -207,71 +209,16 @@ begin
207209
Match_Count : Natural := 0;
208210
Possible_Opcodes : String_Sets.Set;
209211
begin
210-
if Execute ("addr", Sample.Before, A, B, C) = Sample.After then
211-
Match_Count := Match_Count + 1;
212-
Possible_Opcodes.Insert ("addr");
213-
end if;
214-
if Execute ("addi", Sample.Before, A, B, C) = Sample.After then
215-
Match_Count := Match_Count + 1;
216-
Possible_Opcodes.Insert ("addi");
217-
end if;
218-
if Execute ("mulr", Sample.Before, A, B, C) = Sample.After then
219-
Match_Count := Match_Count + 1;
220-
Possible_Opcodes.Insert ("mulr");
221-
end if;
222-
if Execute ("muli", Sample.Before, A, B, C) = Sample.After then
223-
Match_Count := Match_Count + 1;
224-
Possible_Opcodes.Insert ("muli");
225-
end if;
226-
if Execute ("banr", Sample.Before, A, B, C) = Sample.After then
227-
Match_Count := Match_Count + 1;
228-
Possible_Opcodes.Insert ("banr");
229-
end if;
230-
if Execute ("bani", Sample.Before, A, B, C) = Sample.After then
231-
Match_Count := Match_Count + 1;
232-
Possible_Opcodes.Insert ("bani");
233-
end if;
234-
if Execute ("borr", Sample.Before, A, B, C) = Sample.After then
235-
Match_Count := Match_Count + 1;
236-
Possible_Opcodes.Insert ("borr");
237-
end if;
238-
if Execute ("bori", Sample.Before, A, B, C) = Sample.After then
239-
Match_Count := Match_Count + 1;
240-
Possible_Opcodes.Insert ("bori");
241-
end if;
242-
if Execute ("setr", Sample.Before, A, B, C) = Sample.After then
243-
Match_Count := Match_Count + 1;
244-
Possible_Opcodes.Insert ("setr");
245-
end if;
246-
if Execute ("seti", Sample.Before, A, B, C) = Sample.After then
247-
Match_Count := Match_Count + 1;
248-
Possible_Opcodes.Insert ("seti");
249-
end if;
250-
if Execute ("gtir", Sample.Before, A, B, C) = Sample.After then
251-
Match_Count := Match_Count + 1;
252-
Possible_Opcodes.Insert ("gtir");
253-
end if;
254-
if Execute ("gtri", Sample.Before, A, B, C) = Sample.After then
255-
Match_Count := Match_Count + 1;
256-
Possible_Opcodes.Insert ("gtri");
257-
end if;
258-
if Execute ("gtrr", Sample.Before, A, B, C) = Sample.After then
259-
Match_Count := Match_Count + 1;
260-
Possible_Opcodes.Insert ("gtrr");
261-
end if;
262-
if Execute ("eqir", Sample.Before, A, B, C) = Sample.After then
263-
Match_Count := Match_Count + 1;
264-
Possible_Opcodes.Insert ("eqir");
265-
end if;
266-
if Execute ("eqri", Sample.Before, A, B, C) = Sample.After then
267-
Match_Count := Match_Count + 1;
268-
Possible_Opcodes.Insert ("eqri");
269-
end if;
270-
if Execute ("eqrr", Sample.Before, A, B, C) = Sample.After then
271-
Match_Count := Match_Count + 1;
272-
Possible_Opcodes.Insert ("eqrr");
273-
end if;
274-
212+
for I in Opcode_Lookup'Range loop
213+
declare
214+
Op : constant Op_String := Opcode_Lookup (I);
215+
begin
216+
if Execute (Op, Sample.Before, A, B, C) = Sample.After then
217+
Match_Count := Match_Count + 1;
218+
Possible_Opcodes.Insert (Op);
219+
end if;
220+
end;
221+
end loop;
275222
Opcodes (Sample.Instr (0)).Append (Possible_Opcodes);
276223
if Match_Count >= 3 then
277224
Part1_Count := Part1_Count + 1;

0 commit comments

Comments
 (0)