I did something similar. Started with a matrix of possibilities of a-g matching real segments A-G.
Taking acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab | cdfeb fcadb cdfeb cdbaf as an example:-
ab must be a digit 1 so ab must correlate to CF. So it:-
removes all other segments ABDEG as possibility for both a and b
removes all possibilities of C or F from all others (cdefg).
Likewise the item of length 3, dab above, correlates to the segments ACF. The same function above applied to dab, ACF means that d is left only possibly matching A as C and F have been taken away from everything other than a or b.
For the item with 4 segments we do poss( "eafb", "BCDF" )
For the items with 5 segments, if there are 3 unique strings then we know:-
The 3 letters common to all 3 will correlate to ADG
The 2 letters common to only 2 of them will correlate to CF
The 2 letters that only appear in once in all three will correlate to BE
For the items with 6 segments, if there are are 3 unique strings then we know:-
The 4 letters common to all 3 will correlate to ABFG
The 3 letters that only appear in 2 of them will correlate to CDE
Just applying these rules in one pass was enough to leave my map of possibilities to segments with only one match per possibility/segment.
To make it easier I pre-sorted each of the strings in my input.
I did something similar. Started with a matrix of possibilities of a-g matching real segments A-G.
Taking
acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab | cdfeb fcadb cdfeb cdbaf
as an example:-ab
must be a digit 1 soab
must correlate to CF. So it:-ABDEG
as possibility for botha
andb
C
orF
from all others (cdefg
).Likewise the item of length 3,
dab
above, correlates to the segmentsACF
. The same function above applied todab
,ACF
means thatd
is left only possibly matchingA
asC
andF
have been taken away from everything other thana
orb
.For the item with 4 segments we do
poss( "eafb", "BCDF" )
For the items with 5 segments, if there are 3 unique strings then we know:-
ADG
CF
BE
For the items with 6 segments, if there are are 3 unique strings then we know:-
ABFG
CDE
Just applying these rules in one pass was enough to leave my map of possibilities to segments with only one match per possibility/segment.
To make it easier I pre-sorted each of the strings in my input.
Here's the above in perl: https://gist.github.com/alexgreenbank/49b3f43fcd33e96552792dd5e631499d
And here's the debug output showing the progression of the possibility maps for the first simple example given:-