text
stringlengths
0
234
(Index (Digit_Array (Idx), Element (CF_Seg, 2) & "") > 0)
then
if Index (Digit_Array (Idx), Element (CF_Seg, 1) & "") > 0 then
Mapping_Table.Include (Element (CF_Seg, 1), 'f');
Mapping_Table.Include (Element (CF_Seg, 2), 'c');
else
Mapping_Table.Include (Element (CF_Seg, 2), 'f');
Mapping_Table.Include (Element (CF_Seg, 1), 'c');
end if;
Can_Break_CF := True;
end if;
-- Find the number 0 to find corresponding segment of "b" and "d"
if (Index (Digit_Array (Idx), Element (BD_Seg, 1) & "") > 0) /=
(Index (Digit_Array (Idx), Element (BD_Seg, 2) & "") > 0)
then
if Index (Digit_Array (Idx), Element (BD_Seg, 1) & "") > 0 then
Mapping_Table.Include (Element (BD_Seg, 1), 'b');
Mapping_Table.Include (Element (BD_Seg, 2), 'd');
else
Mapping_Table.Include (Element (BD_Seg, 2), 'b');
Mapping_Table.Include (Element (BD_Seg, 1), 'd');
end if;
Can_Break_BD := True;
end if;
if Can_Break_CF and Can_Break_BD then
exit;
end if;
end loop;
for Char in Character range 'a' .. 'g' loop
if not Mapping_Table.Contains (Char) then
EG_Seg := EG_Seg & Char;
end if;
end loop;
-- Find the number 9 to find corresponding segment of "e" and "g"
for Idx in 7 .. 10 loop
if (Index (Digit_Array (Idx), Element (EG_Seg, 1) & "") > 0) /=
(Index (Digit_Array (Idx), Element (EG_Seg, 2) & "") > 0)
then
if Index (Digit_Array (Idx), Element (EG_Seg, 1) & "") > 0 then
Mapping_Table.Include (Element (EG_Seg, 1), 'g');
Mapping_Table.Include (Element (EG_Seg, 2), 'e');
else
Mapping_Table.Include (Element (EG_Seg, 2), 'g');
Mapping_Table.Include (Element (EG_Seg, 1), 'e');
end if;
exit;
end if;
end loop;
return Mapping_Table;
end Get_Corresponding_Segments;
use Segments_To_Digit_Maps;
-- Given a Value, it retrieve the original value according to Mapping_Table.
-- @param Mapping_Table The mapping table that correspond mixed segment signal with the good segment signal
-- @param Value The digit te retrieve
-- @returns Return the resolved digit
function Digit_Reconstruction (Mapping_Table : Mapping_Table_Maps.Map; Value : Digit) return Digit;
--------------------------
-- Digit_Reconstruction --
--------------------------
function Digit_Reconstruction (Mapping_Table : Mapping_Table_Maps.Map; Value : Digit) return Digit is
Result : Digit := Null_Bounded_String;
begin
for Char of To_String (Value) loop
Result := Result & Mapping_Table.Element (Char);
end loop;
declare
Str : String := To_String (Result);
begin
String_Sort (Str);
Result := To_Bounded_String (Str);
Function Definition: procedure Main is
Function Body: use Ada.Execution_Time,
Ada.Real_Time,
Ada.Text_IO;
use Utils;
type Lanternfish_Life_Span is range -1 .. 8;
subtype Long_Long_Natural is Long_Long_Integer range 0 .. Long_Long_Integer'Last;
type Lanternfishes_School is array (Lanternfish_Life_Span) of Long_Long_Natural;
package Lanternfish_Life_Span_IO is new Ada.Text_IO.Integer_IO (Lanternfish_Life_Span);
use Lanternfish_Life_Span_IO;
File : File_Type;
Start_Time, End_Time : CPU_Time;
Execution_Duration : Time_Span;
Lanternfishes : Lanternfishes_School := (others => Long_Long_Natural'First);
Nb_Lanternfishes : Long_Long_Natural := Long_Long_Natural'First;
begin
Get_File (File);