-
Notifications
You must be signed in to change notification settings - Fork 0
/
day6.adb
71 lines (52 loc) · 1.75 KB
/
day6.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
with Ada.Text_IO;
procedure Day6 is
subtype Questions_T is Character range 'a' .. 'z';
type Questions is Array (Questions_T) of Boolean;
Null_Questions : constant Questions := (others => False);
Q_Sum : Natural := 0;
Q_All : Natural := 0;
Line_Questions : Questions := Null_Questions;
Group_Questions : Questions := Null_Questions;
All_Questions : Questions := Null_Questions;
begin
loop
declare
Line : constant String := Ada.Text_IO.Get_Line;
begin
if Line'Length > 0 then
for Q in Line'Range loop
if not Group_Questions (Line(Q)) then
Q_Sum := Q_Sum + 1;
Group_Questions (Line(Q)) := True;
end if;
Line_Questions (Line(Q)) := True;
end loop;
if All_Questions = Null_Questions and then
Group_Questions = Line_Questions then
All_Questions := Line_Questions;
else
All_Questions := All_Questions and Line_Questions;
end if;
Line_Questions := Null_Questions;
else
for Q in Questions_T'Range loop
if All_Questions (Q) then
Q_All := Q_All + 1;
end if;
end loop;
-- Empty line, reset questions array
Group_Questions := Null_Questions;
All_Questions := Null_Questions;
end if;
end;
exit when Ada.Text_IO.End_Of_File;
end loop;
-- Final group
for Q in Questions_T'Range loop
if All_Questions (Q) then
Q_All := Q_All + 1;
end if;
end loop;
Ada.Text_IO.Put_Line("Part 1:" & Q_Sum'Img);
Ada.Text_IO.Put_Line("Part 2:" & Q_All'Img);
end Day6;