text stringlengths 0 234 |
|---|
end if; |
Last := Last + 1; |
elsif Line (Last) = '|' then |
After_Pipe := True; |
Last := Last + 2; |
First := Last; |
else |
Last := Last + 1; |
end if; |
end loop; |
Function Definition: procedure Main is |
Function Body: use Ada.Text_IO; |
use Utils; |
package Digit_Str is new |
Ada.Strings.Bounded.Generic_Bounded_Length (Max => 7); |
use Digit_Str; |
subtype Segment is Character range 'a' .. 'g'; |
subtype Digit is Bounded_String; |
subtype Seven_Segments_Digits is Natural range 0 .. 9; |
-- Sort the characters in a String |
procedure String_Sort is new Ada.Containers.Generic_Array_Sort (Positive, Character, String); |
function Digit_Hash is new Ada.Strings.Bounded.Hash (Digit_Str); |
package Segments_To_Digit_Maps is new Ada.Containers.Indefinite_Hashed_Maps |
(Key_Type => Digit, |
Element_Type => Seven_Segments_Digits, |
Hash => Digit_Hash, |
Equivalent_Keys => "="); |
function Segment_Hash (Elt : Segment) return Ada.Containers.Hash_Type is |
(Ada.Containers.Hash_Type (Segment'Pos (Elt))); |
package Mapping_Table_Maps is new Ada.Containers.Indefinite_Hashed_Maps |
(Key_Type => Segment, |
Element_Type => Segment, |
Hash => Segment_Hash, |
Equivalent_Keys => "="); |
subtype Digits_Array_Index is Positive range 1 .. 10; |
type Digits_Array is array (Digits_Array_Index) of Digit; |
function Is_Lower_Than (Left, Right : Digit) return Boolean is (Length (Left) < Length (Right)); |
procedure Digits_Sort is new Ada.Containers.Generic_Constrained_Array_Sort (Index_Type => Digits_Array_Index, |
Element_Type => Digit, |
Array_Type => Digits_Array, |
"<" => Is_Lower_Than); |
-- Given a String that represent a segment (like "be", or "fgaecd", etc.) it retrieve the corresponding segment. |
-- Note: when the word "associated" is used, it means that we cannot know exactly which segment corresponds |
-- to which other segment. |
-- When the word "corresponding" is used, it means that we know exactly which segment corresponds to which |
-- other segment. |
-- |
-- @param Seg a String that represent a digit |
-- @returns Retruns the corresponding mapping table between segments of digits |
function Get_Corresponding_Segments (Digit_Array : Digits_Array) return Mapping_Table_Maps.Map; |
-------------------------------- |
-- Get_Corresponding_Segments -- |
-------------------------------- |
function Get_Corresponding_Segments (Digit_Array : Digits_Array) return Mapping_Table_Maps.Map is |
use Mapping_Table_Maps; |
Mapping_Table : Mapping_Table_Maps.Map; |
CF_Seg, |
BD_Seg, |
EG_Seg : Digit := Null_Bounded_String; |
Can_Break_CF, |
Can_Break_BD : Boolean := False; |
begin |
-- Get the number 1 to get associated segments "c" and "f" |
CF_Seg := Digit_Array (1); |
-- Get the number 7 to find the corresponding segment of "a" |
for Char of To_String (Digit_Array (2)) loop |
if Index (CF_Seg, Char & "", 1) = 0 then |
Mapping_Table.Include (Char, 'a'); |
exit; |
end if; |
end loop; |
-- Get the number 4 to find associated to "b" and "d" |
for Char of To_String (Digit_Array (3)) loop |
if Index (CF_Seg, Char & "", 1) = 0 then |
BD_Seg := BD_Seg & Char; |
end if; |
end loop; |
for Idx in 7 .. 9 loop |
-- Find the number 6 to find corresponding segment of "f" and "c" |
if (Index (Digit_Array (Idx), Element (CF_Seg, 1) & "") > 0) /= |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.