2022 day 4

This commit is contained in:
2022-12-04 18:03:13 +00:00
parent 4678f22963
commit 35b065f882
3 changed files with 1040 additions and 0 deletions

20
2022/04/part2 Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env python
def build_range(text):
first, last = text.split("-")
return range(int(first), int(last)+1)
count = 0
with open('input') as f:
for line in f:
aS, bS = line.rstrip().split(",")
a = build_range(aS)
b = build_range(bS)
if (a[0] in b or a[-1] in b) or (b[0] in a or b[-1] in a):
count = count + 1
print(count)