From 4ae0d2af7b62f38aaf06dd20f5b6a7a5d9677a67 Mon Sep 17 00:00:00 2001 From: Mika Suhonen Date: Sun, 4 Dec 2022 07:53:53 +0200 Subject: [PATCH] day 4 first answer --- 04/d.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 04/d.py diff --git a/04/d.py b/04/d.py new file mode 100644 index 0000000..e9943ba --- /dev/null +++ b/04/d.py @@ -0,0 +1,28 @@ +import os + +pairs = open(os.path.dirname(__file__) + + "/input.txt", "r").read().splitlines() + +tot1 = 0 +tot2 = 0 + +for p in pairs: + a = p.split(",") + + arrays = [] + + for i in range(0, len(a), 1): + b = a[i].split("-") + + if b[0] == b[1]: + arrays.append([int(b[0])]) + continue + arrays.append(range(int(b[0]), int(b[1])+1)) + + set_a = set(arrays[0]) + set_b = set(arrays[1]) + + if (set_a.issubset(set_b) or set_b.issubset(set_a)): + tot1 += 1 + +print("First answer: " + tot1)