summaryrefslogtreecommitdiff
path: root/2022/04/a.py
diff options
context:
space:
mode:
authorboredpasta <boredpasta@tutanota.com>2025-01-13 07:00:52 +0200
committerboredpasta <boredpasta@tutanota.com>2025-01-13 07:22:23 +0200
commitf85949f85266768ec1bd5e3d150e4ac71feabcf1 (patch)
treea6c81c5ec164d209bf0e664d6a6a22ddd42cd63f /2022/04/a.py
parentaf9283db3825dbfede0a4127a004f0b077fe6f7c (diff)
Add project filesHEADmaster
Diffstat (limited to '2022/04/a.py')
-rw-r--r--2022/04/a.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/2022/04/a.py b/2022/04/a.py
new file mode 100644
index 0000000..73baa96
--- /dev/null
+++ b/2022/04/a.py
@@ -0,0 +1,18 @@
+points = 0
+
+def contains(ran1, ran2):
+ return ran1.start <= ran2.start and ran1.stop >= ran2.stop
+def overlap(ran1, ran2):
+ return ran1.stop >= ran2.start and ran1.start <= ran2.stop
+
+#with open("example") as f:
+with open("input") as f:
+ lines = f.readlines()
+for line in lines:
+ r1, r2 = line.strip().split(",")
+ r11, r12 = list(map(int, r1.split("-")))
+ r21, r22 = list(map(int, r2.split("-")))
+ ran1, ran2 = range(r11, r12), range(r21, r22)
+ if overlap(ran1, ran2):
+ points += 1
+print(points)