From 9f8c9890c3a037ed4b69a041e39f96af54f84a3f Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 9 Dec 2021 11:08:21 +0000 Subject: day 8: cleaned a bit more --- 8.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/8.py b/8.py index 77c9072..99b5502 100644 --- a/8.py +++ b/8.py @@ -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))) -- cgit v1.2.3-54-g00ecf