You are reading a single comment by @Greenbank and its replies. Click here to read the full conversation.
  • 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.

    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:-

    DOING: abcdefg bcdef acdfg abcdf abd abcdef bcdefg abef abcdeg ab -> bcdef abcdf bcdef abcdf
    len=3
       abcdefg
    a: **.*...
    b: ..*.***
    c: **.*...
    d: ..*.***
    e: ..*.***
    f: **.*...
    g: ..*.***
    len=4
       abcdefg
    a: ...*...
    b: ....**.
    c: **.....
    d: ....**.
    e: ..*...*
    f: **.....
    g: ..*...*
    len=2
       abcdefg
    a: ...*...
    b: ....**.
    c: **.....
    d: ....**.
    e: ..*...*
    f: **.....
    g: ..*...*
    DEBUG: Got 3 fives (bcdef abcdf acdfg)
    len=5
       abcdefg
    a: ...*...
    b: ....*..
    c: **.....
    d: .....*.
    e: ......*
    f: **.....
    g: ..*....
    DEBUG: Got 3 sixes (bcdefg abcdeg abcdef)
    len=6
       abcdefg
    a: ...*...
    b: ....*..
    c: *......
    d: .....*.
    e: ......*
    f: .*.....
    g: ..*....
    
About

Avatar for Greenbank @Greenbank started