summaryrefslogtreecommitdiffstats
path: root/4.py
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2022-12-07 12:57:36 +0000
committerTomasz Kramkowski <tomasz@kramkow.ski>2022-12-07 12:57:36 +0000
commitd9a97e9bf28cf91f1a7e57f1298b7c742e25ed56 (patch)
tree999464f801480565733c5223b020b2d762140b00 /4.py
downloadaoc2022-d9a97e9bf28cf91f1a7e57f1298b7c742e25ed56.tar.gz
aoc2022-d9a97e9bf28cf91f1a7e57f1298b7c742e25ed56.tar.xz
aoc2022-d9a97e9bf28cf91f1a7e57f1298b7c742e25ed56.zip
days 1-7
Diffstat (limited to '4.py')
-rw-r--r--4.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/4.py b/4.py
new file mode 100644
index 0000000..3279e7e
--- /dev/null
+++ b/4.py
@@ -0,0 +1,9 @@
+with open('4.in') as f:
+ inp = [tuple(tuple(map(int, elf.split('-'))) for elf in line.rstrip().split(',')) for line in f]
+def fully_contains(a, b):
+ return b[0] >= a[0] and b[1] <= a[1] or a[0] >= b[0] and a[1] <= b[1]
+def overlaps(a, b):
+ return b[0] <= a[0] <= b[1] or b[0] <= a[1] <= b[1] or \
+ a[0] <= b[0] <= a[1] # or a[0] <= b[1] <= a[1]
+print(sum(fully_contains(a, b) for a, b in inp))
+print(sum(overlaps(a, b) for a, b in inp))