text
stringlengths
0
234
Column_Index := Bingo_Range'First;
if Line_Index = Bingo_Range'Last then
Line_Index := Bingo_Range'First;
Boards.Append (Board);
else
Line_Index := Line_Index + 1;
end if;
else
Column_Index := Column_Index + 1;
end if;
Last := Last + 1;
end loop;
Function Definition: procedure Main is
Function Body: use Ada.Execution_Time,
Ada.Real_Time,
Ada.Text_IO;
use Utils;
type Coordinate_2D is record
Line : Natural;
Column : Natural;
end record;
type Folding_Kind is (K_Line, K_Column);
type Folding_T is record
Kind : Folding_Kind;
Value : Natural;
end record;
package Folding_Vectors is new Ada.Containers.Vectors (Natural, Folding_T);
-- This Hash function transform a 2 dimensional location to an unique ID using Cantor pairing enumeration.
-- @param Coord A 2 dimensional location
-- @returns Return the corresponding hash
-- @link https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function
function Hash (Coord : Coordinate_2D) return Ada.Containers.Hash_Type is
(Ada.Containers.Hash_Type (((Coord.Line + Coord.Column) * (Coord.Line + Coord.Column + 1) / 2) + Coord.Column));
function Equivalent_Keys (Left, Right : Coordinate_2D) return Boolean is
(Left.Line = Right.Line and Left.Column = Right.Column);
package Dots_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Coordinate_2D,
Element_Type => Boolean,
Hash => Hash,
Equivalent_Keys => Equivalent_Keys,
"=" => "=");
File : File_Type;
Start_Time, End_Time : CPU_Time;
Execution_Duration : Time_Span;
File_Is_Empty : Boolean := True;
Max_Lines, Max_Columns : Positive := Positive'First;
Folding_Instructions : Folding_Vectors.Vector := Folding_Vectors.Empty_Vector;
Dots_Map : Dots_Maps.Map := Dots_Maps.Empty_Map;
begin
Get_File (File);
-- Get all values
begin
while not End_Of_File (File) loop
declare
Str : constant String := Get_Line (File);
begin
if Str'Length = 0 then
goto Continue_Next_Line;
end if;
if Str (Str'First) = 'f' then
-- "fold along" instruction
declare
use Ada.Integer_Text_IO;
Separator_Index : constant Integer :=
Ada.Strings.Fixed.Index (Source => Str (1 .. Str'Last), Pattern => "=");
Kind : constant String := Str (Separator_Index - 1 .. Separator_Index - 1);
Value_Str : constant String := Str (Separator_Index + 1 .. Str'Last);
Last_Index : Positive := Positive'First;
Value : Natural;
begin
Get (Value_Str, Value, Last_Index);
Folding_Instructions.Append (((if Kind = "x" then K_Column else K_Line), Value));
Function Definition: procedure Main is
Function Body: use Ada.Execution_Time,
Ada.Real_Time,
Ada.Text_IO;
use Utils;
type Coordinate_2D is record
Line : Natural;
Column : Natural;
end record;
type Folding_Kind is (K_Line, K_Column);