text
stringlengths
0
234
if End_Of_File (File) then
raise Program_Error with "Empty file";
end if;
-- Get all Lanternfishes
while not End_Of_File (File) loop
declare
Line : constant String := Get_Line (File);
First : Positive := Line'First;
Last : Positive := Line'First;
Last_Index : Positive := Line'First;
Value : Lanternfish_Life_Span;
begin
while Last <= Line'Last loop
if Line (Last) not in '0' .. '9' then
if Line (First .. Last - 1) /= "" then
Get (Line (First .. Last - 1), Value, Last_Index);
Lanternfishes (Value) := Lanternfishes (Value) + 1;
end if;
First := Last + 1;
Last := First;
elsif Last = Line'Last then
Get (Line (First .. Line'Last), Value, Last_Index);
Lanternfishes (Value) := Lanternfishes (Value) + 1;
Last := Last + 1;
else
Last := Last + 1;
end if;
end loop;
Function Definition: procedure Main is
Function Body: use Ada.Execution_Time,
Ada.Real_Time,
Ada.Text_IO;
use Utils;
type Lanternfish_Life_Span is range -1 .. 8;
subtype Long_Long_Natural is Long_Long_Integer range 0 .. Long_Long_Integer'Last;
type Lanternfishes_School is array (Lanternfish_Life_Span) of Long_Long_Natural;
package Lanternfish_Life_Span_IO is new Ada.Text_IO.Integer_IO (Lanternfish_Life_Span);
use Lanternfish_Life_Span_IO;
File : File_Type;
Start_Time, End_Time : CPU_Time;
Execution_Duration : Time_Span;
Lanternfishes : Lanternfishes_School := (others => Long_Long_Natural'First);
Nb_Lanternfishes : Long_Long_Natural := Long_Long_Natural'First;
begin
Get_File (File);
if End_Of_File (File) then
raise Program_Error with "Empty file";
end if;
-- Get all Lanternfishes
while not End_Of_File (File) loop
declare
Line : constant String := Get_Line (File);
First : Positive := Line'First;
Last : Positive := Line'First;
Last_Index : Positive := Line'First;
Value : Lanternfish_Life_Span;
begin
while Last <= Line'Last loop
if Line (Last) not in '0' .. '9' then
if Line (First .. Last - 1) /= "" then
Get (Line (First .. Last - 1), Value, Last_Index);
Lanternfishes (Value) := Lanternfishes (Value) + 1;
end if;
First := Last + 1;
Last := First;
elsif Last = Line'Last then
Get (Line (First .. Line'Last), Value, Last_Index);
Lanternfishes (Value) := Lanternfishes (Value) + 1;
Last := Last + 1;
else
Last := Last + 1;
end if;
end loop;
Function Definition: procedure Main is
Function Body: use Ada.Execution_Time,
Ada.Real_Time,
Ada.Text_IO;
use Utils;
subtype Chunks is Character
with Static_Predicate => Chunks in
'(' .. '('
| '{' .. '{'
| '[' .. '['
| '<' .. '<'
| ')' .. ')'
| '}' .. '}'
| ']' .. ']'
| '>' .. '>';
subtype Open_Chunks is Chunks
with Static_Predicate => Open_Chunks in