aboutsummaryrefslogtreecommitdiff
path: root/2021/08
diff options
context:
space:
mode:
Diffstat (limited to '2021/08')
-rwxr-xr-x2021/08/puzzle-1.py11
-rwxr-xr-x2021/08/puzzle-2.py8
2 files changed, 10 insertions, 9 deletions
diff --git a/2021/08/puzzle-1.py b/2021/08/puzzle-1.py
index e1ffa7d..9579237 100755
--- a/2021/08/puzzle-1.py
+++ b/2021/08/puzzle-1.py
@@ -3,9 +3,14 @@
def main() -> None:
with open("input", "r", encoding="utf-8") as f:
- data = list(map(lambda l: l.split("|")[1].strip().split(), f.readlines()))
-
- print(sum(sum(len(s) in (2, 3, 4, 7) for s in line) for line in data))
+ print(
+ sum(
+ map(
+ lambda l: sum(map(lambda s: len(s) in (2, 3, 4, 7), l)),
+ map(lambda l: l.split("|")[1].strip().split(), f.readlines()),
+ )
+ )
+ )
if __name__ == "__main__":
diff --git a/2021/08/puzzle-2.py b/2021/08/puzzle-2.py
index 0139049..687c2a7 100755
--- a/2021/08/puzzle-2.py
+++ b/2021/08/puzzle-2.py
@@ -34,11 +34,9 @@ def solve(nums: list[str]) -> int:
nummap[9] = s
else:
nummap[0] = s
-
- nums = nums[nums.index("|") + 1 :]
acc = 0
- for n, (k, v) in itertools.product(nums, nummap.items()):
+ for n, (k, v) in itertools.product(nums[nums.index("|") + 1 :], nummap.items()):
if set(n) == v:
acc = acc * 10 + k
return acc
@@ -46,9 +44,7 @@ def solve(nums: list[str]) -> int:
def main() -> None:
with open("input", "r", encoding="utf-8") as f:
- data = list(map(lambda l: l.strip().split(), f.readlines()))
-
- print(sum(solve(line) for line in data))
+ print(sum(solve(line) for line in map(lambda l: l.strip().split(), f.readlines())))
if __name__ == "__main__":