text stringlengths 0 234 |
|---|
Solve_Puzzle : declare |
Movement : constant Movements := Movements'Value (Line (Line'First .. Index - 1)); |
Value : constant Natural := Natural'Value (Line (Index + 1 .. Line'Last)); |
begin |
case Movement is |
when Forward => |
Horizontal_Position := Horizontal_Position + Value; |
when Down => |
Depth := Depth + Value; |
when Up => |
Depth := Depth - Value; |
end case; |
end Solve_Puzzle; |
exit Split_Value; |
end if; |
end loop Split_Value; |
Function Definition: procedure Main is |
Function Body: use Ada.Text_IO; |
use Utils; |
package L9 renames Ada.Characters.Latin_9; |
type Movements is (Forward, Down, Up); |
File : File_Type; |
Horizontal_Position : Natural := 0; |
Depth : Natural := 0; |
Aim : Natural := 0; |
begin |
Get_File (File); |
-- Get all values |
while not End_Of_File (File) loop |
declare |
Line : constant String := Get_Line (File); |
begin |
Split_Value : for Index in Line'Range loop |
if Line (Index) = L9.Space then |
Solve_Puzzle : declare |
Movement : constant Movements := Movements'Value (Line (Line'First .. Index - 1)); |
Value : constant Natural := Natural'Value (Line (Index + 1 .. Line'Last)); |
begin |
case Movement is |
when Forward => |
Horizontal_Position := Horizontal_Position + Value; |
Depth := Depth + Aim * Value; |
when Down => |
Aim := Aim + Value; |
when Up => |
Aim := Aim - Value; |
end case; |
end Solve_Puzzle; |
exit Split_Value; |
end if; |
end loop Split_Value; |
Function Definition: procedure Main is |
Function Body: use Ada.Text_IO; |
use Utils; |
File : File_Type; |
Result : Natural := Natural'First; |
begin |
Get_File (File); |
if End_Of_File (File) then |
raise Program_Error with "Empty file"; |
end if; |
-- Resolve puzzle while exploring file |
while not End_Of_File (File) loop |
declare |
use Ada.Integer_Text_IO; |
Line : constant String := Get_Line (File); |
First : Positive := Line'First; |
Last : Positive := Line'First; |
Last_Index : Positive := Line'First; |
After_Pipe : Boolean := False; |
Current_Size : Natural := Natural'First; |
begin |
while Last <= Line'Last loop |
if After_Pipe then |
-- Process data |
if Line (Last) = ' ' then |
Current_Size := Last - First; |
First := Last + 1; |
if Current_Size in 2 .. 4 or Current_Size = 7 then |
Result := Result + 1; |
end if; |
elsif Last = Line'Last then |
Current_Size := Last - First + 1; |
First := Last + 1; |
if Current_Size in 2 .. 4 or Current_Size = 7 then |
Result := Result + 1; |
end if; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.