text
stringlengths
0
234
begin
if Can_Delete then
-- Look for empty lines or the opening [[array]]
if Line = "" then
Deletable := Deletable + 1;
elsif
Line = Enter_Marker or else
Has_Prefix (Line, Enter_Marker & '#')
then
-- Now we can delete the empty [[array]] plus any
-- following empty lines.
for J in 0 .. Deletable loop -- 0 for the current line
Lines.Delete (I);
end loop;
-- Restart, we can still delete previous entries
Deletable := 0;
else
-- We found something else, so do not remove entry
Can_Delete := False;
Deletable := 0;
end if;
else
-- Look for a [[ that starts another array entry. We
-- cannot rely on simply [ for tables, these could be
-- nested array tables.
if Has_Prefix (Line, "[[") then
Can_Delete := True;
Deletable := 0;
-- We will look in next iterations for a precedent
-- empty array entry.
end if;
end if;
Function Definition: procedure Day_02 is
Function Body: Mem: constant Memory.Block := Memory.Read_Comma_Separated;
M: aliased Intcode.Machine(Hi_Mem => Mem'Last);
use type Memory.Value;
subtype Input is Memory.Value range 0..99;
begin
for Noun in Input'Range loop
for Verb in Input'Range loop
M.Mem := Mem;
M.Mem(16#1#) := Noun;
M.Mem(16#2#) := Verb;
declare
E: Intcode.Executor(M'Access);
begin
null; -- wait for E to terminate
Function Definition: procedure Day_06 is
Function Body: subtype Name is String(1 .. 3);
You: constant Name := "YOU";
Santa: constant Name := "SAN";
type Orbit is record
Self, Parent: Name;
end record;
type Chain is array (Positive range <>) of Name;
package Orbits is new Ada.Containers.Ordered_Maps(
Key_Type => Name, Element_Type => Orbit);
Locals: Orbits.Map;
function Get(S: String) return Orbit is
begin
for I in S'Range loop
if S(I) = ')' then
return (Parent => S(S'First .. I - 1), Self => S(I + 1 .. S'Last));
end if;
end loop;
raise Constraint_Error with "orbit missing ')': " & S;
end Get;
function Count_Orbits(O: Orbit) return Positive is
E: constant Orbits.Cursor := Locals.Find(O.Parent);
use type Orbits.Cursor;
begin
if E = Orbits.No_Element then
return 1; -- only a direct orbit
else
return 1 + Count_Orbits(Orbits.Element(E));
end if;
end Count_Orbits;
function Ancestors(O: Orbit) return Chain is
Size : constant Natural := Count_Orbits(O) - 1;
C: Chain(1 .. Size);
Curr: Orbit := O;
begin
for I in C'Range loop
C(I) := Curr.Parent;
Curr := Locals.Element(Curr.Parent);
end loop;
return C;