From 743fe407b7ec6f20a4404203211dbb160b9c363e Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Sun, 4 Dec 2022 23:01:00 +0000 Subject: [PATCH] Day4 added --- days1-5/day4/day4.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 days1-5/day4/day4.py diff --git a/days1-5/day4/day4.py b/days1-5/day4/day4.py new file mode 100644 index 0000000..8de296b --- /dev/null +++ b/days1-5/day4/day4.py @@ -0,0 +1,18 @@ +with open('inputs/input4.txt', 'r') as f: + inputContent = f.read().splitlines() + containedCount = 0 + intersectCount = 0 + for line in inputContent: + pair = line.split(',') + startRange1, endRange1 = pair[0].split('-') + startRange2, endRange2 = pair[1].split('-') + if ((int(startRange1) >= int(startRange2) and int(endRange1) <= int(endRange2)) + or (int(startRange2) >= int(startRange1) and int(endRange2) <= int(endRange1))): + containedCount += 1 + + if ((int(endRange1) >= int(startRange2) and int(startRange1) <= int(endRange2)) + or (int(endRange2) >= int(startRange1) and int(startRange2) <= int(endRange1))): + intersectCount += 1 + +print("Contained Count:", containedCount) +print("Intersect Count:", intersectCount)