From cc1c9620678938351ea11cfe67d09ffe4f758deb Mon Sep 17 00:00:00 2001 From: Sijmen Date: Sun, 4 Dec 2022 11:10:52 +0100 Subject: [PATCH] day 4 --- day04.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 day04.py diff --git a/day04.py b/day04.py new file mode 100644 index 0000000..1bd8062 --- /dev/null +++ b/day04.py @@ -0,0 +1,14 @@ +import fileinput + +part1, part2 = 0, 0 + +for line in fileinput.input(): + a, b = line.split(",", 1) + a1, a2 = [int(x) for x in a.split("-", 1)] + b1, b2 = [int(x) for x in b.split("-", 1)] + + part1 += (a1 >= b1 and b2 >= a2) or (b1 >= a1 and a2 >= b2) + part2 += a1 <= b2 and a2 >= b1 + + +print(part1, part2)