Day 4: Camp Cleanup
https://adventofcode.com/2022/day/4
Part One
1 2 3 4 5 6 7 8 9 10 11 12 13
| pair = 0 with open('04.txt', 'r') as fp: for line in fp: line = line.strip() if len(line): l, r = line.split(',') l_s, l_e = map(int, l.split('-')) r_s, r_e = map(int, r.split('-')) if l_s <= r_s and l_e >= r_e: pair += 1 elif r_s <= l_s and r_e >= l_e: pair += 1 print(pair)
|
Answer: 536
Part Two
1 2 3 4 5 6 7 8 9 10 11 12 13
| pair = 0 with open('04.txt', 'r') as fp: for line in fp: line = line.strip() if len(line): l, r = line.split(',') l_s, l_e = map(int, l.split('-')) r_s, r_e = map(int, r.split('-')) if l_e >= r_s and l_s <= r_s: pair += 1 elif r_e >= l_s and r_s <= l_s: pair += 1 print(pair)
|
Answer: 845