Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Part 1
- somma=0
- for line in open('input.txt'):
- a=line.strip().split(',')
- x= list(map(int,a[0].split('-')))
- y = list(map(int, a[1].split('-')))
- #possibile anche farlo con i set e usare x.issubset(y) or y.issubset(x)
- if all( item in list(range(x[0],x[1]+1)) for item in list(range(y[0],y[1]+1))) or all(item in list(range(y[0],y[1]+1)) for item in list(range(x[0],x[1]+1))) :
- somma+=1
- print(somma)
- Part 1 one-line
- print(len(list(filter(lambda x: int(x[0][0])<=int(x[1][0]) and int(x[0][1])>=int(x[1][1]) or (int(x[1][0])<=int(x[0][0]) and int(x[1][1])>=int(x[0][1])),[list(map(lambda x: x.split('-'),l.strip().split(','))) for l in open('input.txt')]))))
- Part 2
- somma=0
- for line in open('input.txt'):
- a=line.strip().split(',')
- x= list(map(int,a[0].split('-')))
- y = list(map(int, a[1].split('-')))
- #possibile anche farlo come in Part 1 ma con any al posto di all
- if set(range(x[0],x[1]+1)).intersection(set(range(y[0],y[1]+1))):
- somma+=1
- print(somma)
- Part 2 one-line
- print(len(list(filter(lambda x: int(x[1][0])<=int(x[0][1]) and int(x[1][0])>=int(x[0][0]) or (int(x[0][0])<=int(x[1][1]) and int(x[0][0])>=int(x[1][0])),[list(map(lambda x: x.split('-'),l.strip().split(','))) for l in open('input.txt')]))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement