Add solution to day 1 part 1 and part 2

This commit is contained in:
Folkert Kevelam 2025-03-16 20:40:53 +01:00
parent d7552fdf02
commit 40991c4e3a

67
AoC/2015/day_1.adb Normal file
View File

@ -0,0 +1,67 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Day_1 is
function Get_Floor( File_Name : String ) return Integer is
File : File_Type;
Sum : Integer := 0;
begin
Open(File, In_File, File_Name);
while not End_Of_File(File) loop
declare
Line : String := Get_Line(File);
begin
for I in Line'Range loop
case Line(I) is
when '(' => Sum := @ + 1;
when ')' => Sum := @ - 1;
when others => null;
end case;
end loop;
end;
end loop;
Close(File);
return Sum;
end Get_Floor;
function Get_Basement_Position( File_Name : String ) return Integer is
File : File_Type;
Position : Natural := 1;
Sum : Integer := 0;
begin
Open(File, In_File, File_Name);
outer_loop:
while not End_Of_File(File) loop
declare
Line : String := Get_Line(File);
begin
for I in Line'Range loop
case Line(I) is
when '(' => Sum := @ + 1;
when ')' =>
Sum := @ - 1;
if Sum = -1 then
exit outer_loop;
end if;
when others => null;
end case;
Position := @ + 1;
end loop;
end;
end loop outer_loop;
Close(File);
return Position;
end Get_Basement_Position;
begin
Put_Line(Get_Floor("input_day_1.txt")'Image);
Put_Line(Get_Basement_Position("input_day_1.txt")'Image);
end Day_1;