2022 - Day 4 part 1

This commit is contained in:
kleph 2022-12-04 13:15:13 +01:00
parent 87a8ee1022
commit 20217999fe
4 changed files with 1027 additions and 1 deletions

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python
# 2022 - Advent Of Code 3 - part2
# 2022 - Advent Of Code 3 - part1
# file = 'input_example.txt'
file = 'input.txt'

20
2022/4/4.py Normal file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env python
# 2022 - Advent Of Code 4
# file = 'input_example.txt'
file = 'input.txt'
overlap = 0
with open(file, encoding="utf-8") as f:
ranges_list = [line.strip().split(',') for line in f.readlines()]
for ranges in ranges_list:
elf1_r = ranges[0].split('-')
elf2_r = ranges[1].split('-')
if int(elf1_r[0]) <= int(elf2_r[0]) and int(elf1_r[1]) >= int(elf2_r[1]):
print(f"1range {elf2_r} is contained in {elf1_r}")
overlap += 1
elif int(elf2_r[0]) <= int(elf1_r[0]) and int(elf2_r[1]) >= int(elf1_r[1]):
print(f"2range {elf1_r} is contained in {elf2_r}")
overlap += 1
print(overlap)

1000
2022/4/input.txt Normal file

File diff suppressed because it is too large Load diff

6
2022/4/input_example.txt Normal file
View file

@ -0,0 +1,6 @@
2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8