-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday04.py
29 lines (24 loc) · 816 Bytes
/
day04.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# input = """2-4,6-8
# 2-3,4-5
# 5-7,7-9
# 2-8,3-7
# 6-6,4-6
# 2-6,4-8""".split("\n")
file = open("day04_input.txt", "r")
input = file.read().splitlines()
file.close()
# count = 0
# for line in input:
# elf1_start, elf1_end, elf2_start, elf2_end = [int(x) for elfs in line.split(",") for x in elfs.split("-")]
# elf1 = list(range(elf1_start, elf1_end + 1))
# elf2 = list(range(elf2_start, elf2_end + 1))
# count += 1 if set(elf1).issubset(elf2) or set(elf2).issubset(elf1) else 0
#
# print(count)
count = 0
for line in input:
elf1_start, elf1_end, elf2_start, elf2_end = [int(x) for elfs in line.split(",") for x in elfs.split("-")]
elf1 = list(range(elf1_start, elf1_end + 1))
elf2 = list(range(elf2_start, elf2_end + 1))
count += 1 if set(elf1) & set(elf2) else 0
print(count)