text stringlengths 0 234 |
|---|
when ']' => |
Snailfish_Number.Append (Closing_Bracket); |
when '0' .. '9' => |
Ada.Integer_Text_IO.Get (Char & "", Value, Last); |
Snailfish_Number.Append (Value); |
when others => |
null; |
end case; |
File_Is_Empty := False; |
end loop; |
Input.Append (Snailfish_Number); |
Function Definition: procedure Main is |
Function Body: use Ada.Execution_Time, |
Ada.Real_Time, |
Ada.Text_IO; |
use Utils; |
Opening_Bracket : constant := -2; |
Closing_Bracket : constant := -1; |
subtype Snailfish_Values is Integer range Opening_Bracket .. Integer'Last; |
package Snailfish_Math_List is new Ada.Containers.Doubly_Linked_Lists (Element_Type => Snailfish_Values, |
"=" => "="); |
use Snailfish_Math_List; |
function "+" (Left, Right : List) return List; |
function "+" (Left, Right : List) return List is |
Result : List := Copy (Left); |
begin |
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"; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.