Initial commit
This commit is contained in:
commit
b1394d905a
18 changed files with 6496 additions and 0 deletions
22
day5/1.py
Normal file
22
day5/1.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
with open(r'day5/input.txt', 'r') as input:
|
||||
lines = input.read().split('\n')[:-1]
|
||||
|
||||
blank = lines.index('')
|
||||
|
||||
ranges = []
|
||||
|
||||
for i in range(blank):
|
||||
ranges.append(list(map(lambda x: int(x), lines[i].split('-'))))
|
||||
|
||||
print(ranges)
|
||||
|
||||
sum = 0
|
||||
|
||||
for i in range(blank+1,len(lines)):
|
||||
id = int(lines[i])
|
||||
for range in ranges:
|
||||
if range[0] <= id and range[1] >= id:
|
||||
sum+=1
|
||||
break
|
||||
|
||||
print(sum)
|
||||
19
day5/2.py
Normal file
19
day5/2.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
with open(r'day5/input.txt', 'r') as input:
|
||||
lines = input.read().split('\n')[:-1]
|
||||
|
||||
blank = lines.index('')
|
||||
ranges = [list(map(lambda x: int(x), lines[i].split('-'))) for i in range(blank)]
|
||||
|
||||
ranges.sort(key=lambda x: x[0])
|
||||
sum = 0
|
||||
|
||||
while ranges != []:
|
||||
maxi = ranges[0][1]
|
||||
mini = ranges[0][0]
|
||||
ranges.pop(0)
|
||||
while ranges != [] and ranges[0][0] <= maxi :
|
||||
maxi = max(ranges[0][1],maxi)
|
||||
ranges.pop(0)
|
||||
sum += maxi-mini +1
|
||||
|
||||
print(sum)
|
||||
1174
day5/input.txt
Normal file
1174
day5/input.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue