diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-09 11:08:21 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-09 11:08:21 +0000 |
commit | 9f8c9890c3a037ed4b69a041e39f96af54f84a3f (patch) | |
tree | f8556c54a3b2b0ce3bfa25695d1758bf7fe38518 | |
parent | 3669b9d31e39ddb53bbcc40e98c5e2471ee41e8a (diff) | |
download | aoc2021-9f8c9890c3a037ed4b69a041e39f96af54f84a3f.tar.gz aoc2021-9f8c9890c3a037ed4b69a041e39f96af54f84a3f.tar.xz aoc2021-9f8c9890c3a037ed4b69a041e39f96af54f84a3f.zip |
day 8: cleaned a bit more
-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))) |