From f0df6b8c8cd2f02fdb952fa7121980e5710efbce Mon Sep 17 00:00:00 2001 From: kwout Date: Mon, 4 Dec 2023 11:25:04 -0500 Subject: [PATCH] 2023 day 4 part 1 solved --- 2023/4.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 2023/4.py diff --git a/2023/4.py b/2023/4.py new file mode 100644 index 0000000..887cc49 --- /dev/null +++ b/2023/4.py @@ -0,0 +1,12 @@ +lines = [(int(m[0][-1]), [[int(o) for o in n.split(" ") if o!= ""] for n in m[1].split(" | ")]) for m in [l.split(": ") for l in open("input.txt", "r").read().splitlines()]] + +summa = 0 + +for l in lines: + hits = len(set(l[1][0]).intersection(l[1][1])) + summa += pow(2, hits-1) if hits > 0 else 0 + +print(summa) + +#cursed one line solution to part 1 +#print(sum([int(pow(2, len(set(l[1][0]).intersection(l[1][1]))-1)) for l in [(int(m[0][-1]), [[int(o) for o in n.split(" ") if o!= ""] for n in m[1].split(" | ")]) for m in [l.split(": ") for l in open("input.txt", "r").read().splitlines()]]])) \ No newline at end of file