Advent of Code occurs at Dec 01 to 25 where each day, you will need to solve a puzzle. It is Festival and the problem statement is mostly related to Christmas.
Day 4 - Camp Cleanup
https://adventofcode.com/2022/day/4
Q1
import sys
file1 = open(sys.argv[1], "r")
ans = 0
while True:
line = file1.readline()
if not line:
break
line = line.strip()
if not line:
break
arr = line.split(',')
a, b = map(int, arr[0].split('-'))
c, d = map(int, arr[1].split('-'))
if (a >= c and b <= d) or (c >= a and d <= b):
ans += 1
print(ans)
Q2
import sys
file1 = open(sys.argv[1], "r")
ans = 0
while True:
line = file1.readline()
if not line:
break
line = line.strip()
if not line:
break
arr = line.split(',')
a, b = map(int, arr[0].split('-'))
c, d = map(int, arr[1].split('-'))
if not (b < c or a > d):
print(a, b, c, d)
ans += 1
print(ans)
Today is about the interval intersection