Advertisement
ahti123

AoC 2022 d4

Dec 4th, 2022
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. with open('inp1.txt') as f:
  2.     data = list(map(
  3.         lambda x: list(map(lambda y: list(map(int, y.split('-'))), x.split(','))),
  4.         f.read().split('\n')
  5.     ))
  6.  
  7. def _overlaps_completely(item):
  8.     if item[0][0] > item[1][0]:
  9.         return item[0][1] <= item[1][1]
  10.     if item[0][0] < item[1][0]:
  11.         return item[0][1] >= item[1][1]
  12.     return item[0][0] == item[1][0] or item[0][1] == item[1][1]
  13.  
  14. def part1():
  15.     print(len(list(filter(_overlaps_completely, data))))
  16.  
  17. def _overlaps(item):
  18.     if item[0][0] < item[1][0]:
  19.         return item[0][1] >= item[1][0]
  20.     if item[0][0] > item[1][0]:
  21.         return item[0][0] <= item[1][1]
  22.     return True
  23.  
  24. def part2():
  25.     print(len(list(filter(_overlaps, data))))
  26.  
  27. if __name__ == '__main__':
  28.     part2()
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement