From 40991c4e3a5f868b885ddbeba81f74a96a1e2180 Mon Sep 17 00:00:00 2001 From: Folkert Kevelam Date: Sun, 16 Mar 2025 20:40:53 +0100 Subject: [PATCH] Add solution to day 1 part 1 and part 2 --- AoC/2015/day_1.adb | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 AoC/2015/day_1.adb diff --git a/AoC/2015/day_1.adb b/AoC/2015/day_1.adb new file mode 100644 index 0000000..1f91de8 --- /dev/null +++ b/AoC/2015/day_1.adb @@ -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;