2022 day 4
This commit is contained in:
1000
2022/04/input
Normal file
1000
2022/04/input
Normal file
File diff suppressed because it is too large
Load Diff
20
2022/04/part1
Executable file
20
2022/04/part1
Executable 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 and a[-1] in b) or (b[0] in a and b[-1] in a):
|
||||||
|
count = count + 1
|
||||||
|
|
||||||
|
print(count)
|
||||||
|
|
||||||
|
|
20
2022/04/part2
Executable file
20
2022/04/part2
Executable 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)
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user