diff options
Diffstat (limited to '2022/04/a.py')
-rw-r--r-- | 2022/04/a.py | 18 |
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) |