diff options
Diffstat (limited to '8.py')
-rw-r--r-- | 8.py | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -28,7 +28,7 @@ with open_day(8) as f: patterns, digits = line.rstrip().split(' | ') patterns = fset(fset(p) for p in patterns.split()) countmap = { - count: seg + count: fset((seg,)) for seg, count in Counter(chain.from_iterable(patterns)).items() } lenmap = { len(pat): pat for pat in patterns } @@ -36,16 +36,15 @@ with open_day(8) as f: BCDF = lenmap[len(dig[4])] ACF = lenmap[len(dig[7])] ABCDEFG = lenmap[len(dig[8])] - segmap = dict() - segmap[Seg.B] = countmap[len(seg[Seg.B])] - segmap[Seg.E] = countmap[len(seg[Seg.E])] - segmap[Seg.F] = countmap[len(seg[Seg.F])] - def single(s): return next(iter(s)) - segmap[Seg.A] = single(ACF - CF) - segmap[Seg.C] = single(CF - fset(segmap[Seg.F])) - segmap[Seg.D] = single(BCDF - CF - fset(segmap[Seg.B])) - segmap[Seg.G] = single(ABCDEFG - fset(segmap.values())) - digmap = { fset(segmap[s] for s in d): i for i, d in enumerate(dig) } + B = countmap[len(seg[Seg.B])] + E = countmap[len(seg[Seg.E])] + F = countmap[len(seg[Seg.F])] + A = ACF - CF + C = CF - F + D = BCDF - CF - B + G = ABCDEFG - A - BCDF - E + segmap = [ A, B, C, D, E, F, G ] + digmap = { fset(next(iter(segmap[s])) for s in d): i for i, d in enumerate(dig) } digits = [ digmap[fset(d)] for d in digits.split() ] counts.update(digits) count += sum(d * 10 ** i for i, d in enumerate(reversed(digits))) |