From 6b9ff21a5a59a8963673909abd5ee94a0ae806d5 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Wed, 8 Dec 2021 17:00:30 +0100 Subject: [PATCH] 2021 day8/python: add fast solution --- 2021/day8/fast.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 2021/day8/fast.py diff --git a/2021/day8/fast.py b/2021/day8/fast.py new file mode 100755 index 0000000..a0aff5f --- /dev/null +++ b/2021/day8/fast.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +import sys +from collections import Counter + +if __name__ == '__main__': + acc1 = 0 + acc2 = 0 + for line in sys.stdin.readlines(): + inputs, outputs = line.split('|') + counter = Counter(c for cs in inputs for c in cs) + digits = [{17: 1, 25: 7, 30: 4, 34: 2, 37: 5, 39: 3, 41: 6, 42: 0, 49: 8, 45: 9}[sum(counter[c] for c in output)] for output in outputs.strip().split()] + acc1 += sum(digit in (1, 4, 7, 8) for digit in digits) + acc2 += int(''.join(str(digit) for digit in digits)) + print(acc1) + print(acc2)