My Advent of Code solutions in Python.
kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code
python
1import fileinput
2
3
4part_1 = 0
5part_2 = 0
6
7for line in fileinput.input():
8 elf_1, elf_2 = line.strip().split(',')
9 a, b = [int(x) for x in elf_1.split('-')]
10 c, d = [int(x) for x in elf_2.split('-')]
11
12 # Part 1
13 if a <= c <= b and a <= d <= b:
14 part_1 += 1
15 elif c <= a <= d and c <= b <= d:
16 part_1 += 1
17
18
19 # Part 2
20 if a <= c <= b or a <= d <= b:
21 part_2 += 1
22 elif c <= a <= d or c <= b <= d:
23 part_2 += 1
24
25print("Part 1:", part_1)
26print("Part 2:", part_2)