day4 complete!

This commit is contained in:
Colin Diem
2022-12-12 20:56:19 -05:00
parent 2cc91de95d
commit 5fd3f79810

View File

@@ -1,4 +1,11 @@
input = open("./test.txt", "r") input = open("./input.txt", "r")
def inRange(num, start, end):
if (num < start):
return False
if (num > end):
return False
return start <= num <= end
total = 0 total = 0
@@ -9,10 +16,19 @@ for line in input:
elf1 = [int(elf1[0]), int(elf1[1])] elf1 = [int(elf1[0]), int(elf1[1])]
elf2 = elves[1].split("-") elf2 = elves[1].split("-")
elf2 = [int(elf2[0]), int(elf2[1])] elf2 = [int(elf2[0]), int(elf2[1])]
if (elf1[0] <= elf2[0] and elf1[1] >= elf2[1]): elf2 = range(elf2[0], elf2[1] + 1)
elf1 = range(elf1[0], elf1[1] + 1)
elf1IsInElf2Range = False
elf2IsInElf1Range = False
for numbr in elf1:
if (inRange(numbr, elf2[0], elf2[len(elf2) - 1])):
elf1IsInElf2Range = True
break
for numbr in elf2:
if (inRange(numbr, elf1[0], elf1[len(elf1) - 1])):
elf2IsInElf1Range = True
break
if (elf2IsInElf1Range or elf1IsInElf2Range):
total += 1 total += 1
elif (elf2[0] <= elf1[0] and elf2[1] >= elf1[1]):
total += 1
elif(elf1[0] >= elf2[0] or elf)
print(total) print(total)