text
stringlengths
0
234
Result.Prepend (New_Item => Opening_Bracket,
Count => 1);
for Elt of Right loop
Result.Append (Elt);
end loop;
Result.Append (Closing_Bracket);
return Result;
end "+";
function "+" (Left : Snailfish_Math_List.Cursor; Right : Positive) return Snailfish_Math_List.Cursor;
function "+" (Left : Snailfish_Math_List.Cursor; Right : Positive) return Snailfish_Math_List.Cursor is
Result : Snailfish_Math_List.Cursor := Left;
begin
for Index in 1 .. Right loop
Result := Next (Result);
end loop;
return Result;
end "+";
function "-" (Left : Snailfish_Math_List.Cursor; Right : Positive) return Snailfish_Math_List.Cursor;
function "-" (Left : Snailfish_Math_List.Cursor; Right : Positive) return Snailfish_Math_List.Cursor is
Result : Snailfish_Math_List.Cursor := Left;
begin
for Index in 1 .. Right loop
Result := Previous (Result);
end loop;
return Result;
end "-";
procedure Put (Snailfish_Number : List);
procedure Put (Snailfish_Number : List) is
Curs : Snailfish_Math_List.Cursor := Snailfish_Number.First;
begin
while Has_Element (Curs) loop
case Element (Curs) is
when Opening_Bracket =>
Put ("[");
when Closing_Bracket =>
Put ("]");
if Has_Element (Curs + 1) and then Element (Curs + 1) = Opening_Bracket then
Put (", ");
end if;
when others =>
if Element (Curs - 1) > Closing_Bracket then
Put (", ");
end if;
Ada.Integer_Text_IO.Put (Item => Element (Curs), Width => 0);
end case;
Curs := Curs + 1;
end loop;
end Put;
package Snailfish_Math_Vectors is new Ada.Containers.Vectors (Index_Type => Natural,
Element_Type => List,
"=" => "=");
use Snailfish_Math_Vectors;
function Pop (Vec : in out Vector) return List;
function Pop (Vec : in out Vector) return List is
Result : List;
begin
if Vec.Is_Empty then
raise Constraint_Error with "Container is empty";
end if;
Result := Vec.First_Element;
Vec.Delete_First;
return Result;
end Pop;
File : File_Type;
Start_Time, End_Time : CPU_Time;
Execution_Duration : Time_Span;
File_Is_Empty : Boolean := True;
Result : Natural := Natural'First;
Result_List : List;
Input : Vector;
begin
Get_File (File);
-- Get all values
declare
begin
while not End_Of_File (File) loop
declare
Str : constant String := Get_Line (File);
Last : Positive;
Value : Natural;
Snailfish_Number : List;
begin
for Char of Str loop
case Char is
when '[' =>
Snailfish_Number.Append (Opening_Bracket);