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;