Advertisement
GalinaKG

Advent of code - Day 4 - First task

Dec 4th, 2022
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. counter = 0
  2.  
  3. with open("text.txt", "r") as input_data:
  4.     for line in input_data:
  5.         line = line.strip("\n")
  6.         first_pair, second_pair = line.split(",")
  7.         first_num1, second_num1 = first_pair.split("-")
  8.         first_num2, second_num2 = second_pair.split("-")
  9.         first_range = set([i for i in range(int(first_num1), int(second_num1) + 1)])
  10.         second_range = set([i for i in range(int(first_num2), int(second_num2) + 1)])
  11.         if first_range.issubset(second_range) or second_range.issubset(first_range):
  12.             counter += 1
  13.  
  14. print(counter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement