summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2022-12-13 11:07:46 +0000
committerTomasz Kramkowski <tomasz@kramkow.ski>2022-12-13 11:07:46 +0000
commit64858ccab6111ec35eee369c5b2a4d7f8b1f795c (patch)
tree817936a1df1cea7b1e604d4a286a0012b60acb78
parentb74203979d10a97d4c0635469c4e5536840eafbf (diff)
downloadaoc2022-64858ccab6111ec35eee369c5b2a4d7f8b1f795c.tar.gz
aoc2022-64858ccab6111ec35eee369c5b2a4d7f8b1f795c.tar.xz
aoc2022-64858ccab6111ec35eee369c5b2a4d7f8b1f795c.zip
13 chain from iterable
-rw-r--r--13.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/13.py b/13.py
index 5c1fa34..9282fdf 100644
--- a/13.py
+++ b/13.py
@@ -1,13 +1,14 @@
from utils import open_day
from ast import literal_eval
from functools import cmp_to_key
+from itertools import chain
with open_day(13) as f:
pairs = [tuple(literal_eval(v) for v in p.split('\n')) for p in f.read().rstrip().split('\n\n')]
def compare(l, r):
match (l, r):
- case ([*l], [*r]):
+ case ( [*l], [*r]):
for a, b in zip(l, r):
cmp = compare(a, b)
if cmp != 0: return cmp
@@ -22,9 +23,6 @@ for i, (l, r) in enumerate(pairs):
if cmp < 0: p1 += i + 1
print(p1)
-p2 = [[[2]],[[6]]]
-for l, r in pairs:
- p2.append(l)
- p2.append(r)
+p2 = [[[2]], [[6]], *chain.from_iterable(pairs)]
p2.sort(key=cmp_to_key(compare))
print((p2.index([[2]]) + 1) * (p2.index([[6]]) + 1))