-
Notifications
You must be signed in to change notification settings - Fork 0
/
day2.adb
64 lines (47 loc) · 1.58 KB
/
day2.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
with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Strings.Fixed;
procedure Day2 is
Min_Length : Natural;
Max_Length : Natural;
Line_Pos : Natural;
Check_Char : Character;
N_Of_Char : Natural;
N_Valid_Part1 : Natural := 0;
N_Valid_Part2 : Natural := 0;
begin
loop
declare
Line : String := Ada.Text_IO.Get_Line;
begin
Ada.Integer_Text_IO.Get(Line, Min_Length, Line_Pos);
Line_Pos := Line_Pos + 1; -- Skip over the '-'
Ada.Strings.Fixed.Delete (Line, 1, Line_Pos);
Ada.Integer_Text_IO.Get(Line, Max_Length, Line_Pos);
Line_Pos := Line_Pos + 2; -- Skip over the ' '
Check_Char := Line (Line_Pos);
Ada.Strings.Fixed.Delete (Line, 1, Line_Pos + 2); -- Skip over the 'x: '
N_Of_Char := 0;
for Char in Line'Range loop
if Line (Char) = Check_Char then
N_Of_Char := N_Of_Char +1;
end if;
end loop;
if N_Of_Char >= Min_Length and then
N_Of_Char <= Max_Length
then
N_Valid_Part1 := N_Valid_Part1 + 1;
end if;
if (Line (Min_Length) = Check_Char and then
Line (Max_Length) /= Check_Char) or else
(Line (Min_Length) /= Check_Char and then
Line (Max_Length) = Check_Char)
then
N_Valid_Part2 := N_Valid_Part2 + 1;
end if;
end;
exit when Ada.Text_IO.End_Of_File;
end loop;
Ada.Text_IO.Put_Line("Valid 1: " & N_Valid_Part1'Img);
Ada.Text_IO.Put_Line("Valid 2: " & N_Valid_Part2'Img);
end Day2;