Day 4 2022
This commit is contained in:
parent
6942ecceb3
commit
adc1f4a005
3 changed files with 1036 additions and 0 deletions
1000
Python/2022/04/input
Normal file
1000
Python/2022/04/input
Normal file
File diff suppressed because it is too large
Load diff
30
Python/2022/04/main.py
Normal file
30
Python/2022/04/main.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
input = open("input", 'r')
|
||||
# input = open("sample", 'r')
|
||||
|
||||
data = []
|
||||
data2 = []
|
||||
|
||||
total = 0
|
||||
total2 = 0
|
||||
|
||||
for line in input:
|
||||
pair = line.strip().split(",")
|
||||
r1 = pair[0].split("-")
|
||||
r2 = pair[1].split("-")
|
||||
|
||||
if int(r1[0]) <= int(r2[0]) and int(r1[1]) >= int(r2[1]):
|
||||
total += 1
|
||||
elif int(r2[0]) <= int(r1[0]) and int(r2[1]) >= int(r1[1]):
|
||||
total += 1
|
||||
|
||||
for i in range(int(r1[0]),int(r1[1])+1):
|
||||
for j in range(int(r2[0]),int(r2[1])+1):
|
||||
if i == j:
|
||||
total2 += 1
|
||||
break
|
||||
if i == j:
|
||||
break
|
||||
|
||||
|
||||
print(total)
|
||||
print(total2)
|
||||
6
Python/2022/04/sample
Normal file
6
Python/2022/04/sample
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
2-4,6-8
|
||||
2-3,4-5
|
||||
5-7,7-9
|
||||
2-8,3-7
|
||||
6-6,4-6
|
||||
2-6,4-8
|
||||
Loading…
Add table
Add a link
Reference in a new issue