text
stringlengths
0
234
Str : constant String := Get_Line (File);
Value : Hegiht;
Last : Positive;
begin
if Array_Width = Natural'First then
Array_Width := Str'Length;
end if;
for Char of Str loop
Ada.Integer_Text_IO.Get (Char & "", Value, Last);
Values.Append (Value);
end loop;
Function Definition: procedure Main is
Function Body: use Ada.Containers,
Ada.Execution_Time,
Ada.Real_Time,
Ada.Text_IO;
use Utils;
type Bingo_Range is range 1 .. 5;
subtype Bingo_Values is Natural range 0 .. 99;
package Bingo_Values_IO is new Ada.Text_IO.Integer_IO (Bingo_Values);
use Bingo_Values_IO;
type Grid_Element is record
Value : Bingo_Values;
Marked : Boolean;
end record;
type Lookup_Item is record
Board_Id : Natural;
Line : Bingo_Range;
Column : Bingo_Range;
end record;
package Lookup_Item_Vectors is new Ada.Containers.Vectors (Natural, Lookup_Item);
function Bingo_Range_Hash (Elt : Bingo_Values) return Ada.Containers.Hash_Type is (Ada.Containers.Hash_Type (Elt));
package Lookup_Map is new Ada.Containers.Hashed_Maps (Key_Type => Bingo_Values,
Element_Type => Lookup_Item_Vectors.Vector,
Hash => Bingo_Range_Hash,
Equivalent_Keys => "=",
"=" => Lookup_Item_Vectors."=");
use Lookup_Map;
-- Given a Lookup map, it add an element to the specified value.
-- @param Lookup Lookup map to update
-- @param Value Id in the map "Lookup"
-- @param Board_Id Property of the Lookup_Item that will be added to the vector at id "Value"
-- @param Line Property of the Lookup_Item that will be added to the vector at id "Value"
-- @param Column Property of the Lookup_Item that will be added to the vector at id "Value"
procedure Update_Lookup (Lookup : in out Map; Value : Bingo_Values; Board_Id : Natural; Line, Column : Bingo_Range);
-------------------
-- Update_Lookup --
-------------------
procedure Update_Lookup (Lookup : in out Map; Value : Bingo_Values; Board_Id : Natural; Line, Column : Bingo_Range)
is
use Lookup_Item_Vectors;
Item : constant Lookup_Item := (Board_Id, Line, Column);
Vec : Lookup_Item_Vectors.Vector := Lookup.Element (Value);
begin
Vec.Append (Item);
Lookup.Replace_Element (Lookup.Find (Value), Vec);
end Update_Lookup;
type Grid is array (Bingo_Range, Bingo_Range) of Grid_Element;
package Grid_Vectors is new Ada.Containers.Vectors (Natural, Grid);
use Grid_Vectors;
package Bingo_Values_Queue_Interfaces is
new Ada.Containers.Synchronized_Queue_Interfaces
(Element_Type => Bingo_Values);
package Bingo_Balls is new Ada.Containers.Unbounded_Synchronized_Queues
(Queue_Interfaces => Bingo_Values_Queue_Interfaces);
use Bingo_Balls;
-- Tell if there is a bingo.
-- @param Board The board to check
-- @param Line The marked line
-- @param Column The marked column
-- @returns Return True if there is a bingo, False otherwise
function Is_Bingo (Board : Grid; Line, Column : Bingo_Range) return Boolean;
--------------
-- Is_Bingo --
--------------
function Is_Bingo (Board : Grid; Line, Column : Bingo_Range) return Boolean is
Line_Bingo, Column_Bingo : Boolean := True;
begin
for Index in Bingo_Range loop
Line_Bingo := Line_Bingo and Board (Index, Column).Marked;
Column_Bingo := Column_Bingo and Board (Line, Index).Marked;