From cf05f33d2ede850514c963131bf015711250e015 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Mon, 30 Sep 2024 09:09:00 +0200 Subject: [PATCH] simpler version of 4-1 --- 4/onestar-1.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 4/onestar-1.py diff --git a/4/onestar-1.py b/4/onestar-1.py new file mode 100644 index 0000000..a767e27 --- /dev/null +++ b/4/onestar-1.py @@ -0,0 +1,25 @@ +elves = [] +count = 0 +with open("input.txt", "r") as f: + for line in f.readlines(): + line = line.strip("\n") + # "A-B,C-D" + twoelves = line.split(",") + # ["A-B", "C-D"] + + # "A-B" + leftelf = twoelves[0].split("-") + # ["A", "B"] + lb1 = int(leftelf[0]) + ub1 = int(leftelf[1]) + + # "C-D" + rightelf = twoelves[1].split("-") + # ["C", "D"] + lb2 = int(rightelf[0]) + ub2 = int(rightelf[1]) + + if ((lb1 <= lb2 and ub1 >= ub2) or # Elf 1 fully covers elf 2 + (lb2 <= lb1 and ub2 >= ub1)): # Elf 2 fully covers elf 1 + count += 1 +print(count) \ No newline at end of file