Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open('inp1.txt') as f:
- data = list(map(
- lambda x: list(map(lambda y: list(map(int, y.split('-'))), x.split(','))),
- f.read().split('\n')
- ))
- def _overlaps_completely(item):
- if item[0][0] > item[1][0]:
- return item[0][1] <= item[1][1]
- if item[0][0] < item[1][0]:
- return item[0][1] >= item[1][1]
- return item[0][0] == item[1][0] or item[0][1] == item[1][1]
- def part1():
- print(len(list(filter(_overlaps_completely, data))))
- def _overlaps(item):
- if item[0][0] < item[1][0]:
- return item[0][1] >= item[1][0]
- if item[0][0] > item[1][0]:
- return item[0][0] <= item[1][1]
- return True
- def part2():
- print(len(list(filter(_overlaps, data))))
- if __name__ == '__main__':
- part2()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement