From 7b6a7a64f90372d0a459d5c15cdb06b36b86ca9f Mon Sep 17 00:00:00 2001 From: Atvars Karro Date: Fri, 10 Dec 2021 08:36:09 +0200 Subject: [PATCH] Day 10, with some _reduction_ --- day10.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/day10.py b/day10.py index cb00f3f..8b94330 100644 --- a/day10.py +++ b/day10.py @@ -1,3 +1,4 @@ +from functools import reduce data = open("data/day10.txt", "r").read().splitlines() val = { @@ -21,10 +22,7 @@ try: s += next(val[i] for i in d if i in ">}])") except StopIteration: - sc = 0 - for v in d[::-1]: - sc = sc * 5 + val[v] - inc.append(sc) + inc.append(reduce(lambda a, b: a * 5 + b, [val[v] for v in d[::-1]])) inc = sorted(inc)