From 569b2b6f05fb849d3bea8a6f4c426267ceb0b7e5 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Sat, 2 Dec 2023 16:43:17 +0100 Subject: [PATCH] Small optimization --- d02.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/d02.py b/d02.py index 467bfb1..0337add 100755 --- a/d02.py +++ b/d02.py @@ -2,5 +2,5 @@ from sys import argv inp = {int(x.split()[1]): [{a.split()[1]: int(a.split()[0]) for a in z.split(",")} for z in y.split(";")] for x, y in map(lambda x: x.split(":"), open(argv[1]).readlines())} -print(sum([x for x, y in inp.items() if all([z.get("red", 0) <= 12 and z.get("green", 0) <= 13 and z.get("blue", 0) <= 14 for z in y])])) +print(sum(x for x, y in inp.items() if all(z.get("red", 0) <= 12 and z.get("green", 0) <= 13 and z.get("blue", 0) <= 14 for z in y))) print(sum(max(map(lambda x: x.get("red", 0), y)) * max(map(lambda x: x.get("green", 0), y)) * max(map(lambda x: x.get("blue", 0), y)) for x, y in inp.items()))