Move into 2022 folder
This commit is contained in:
+1000
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
||||
count = 0
|
||||
with open("input.txt", "r") as f:
|
||||
for line in f.readlines():
|
||||
line = line.strip("\n")
|
||||
# "A-B,C-D"
|
||||
twoelves = line.split(",")
|
||||
# ["A-B", "C-D"]
|
||||
|
||||
# "A-B"
|
||||
leftelf = twoelves[0].split("-")
|
||||
# ["A", "B"]
|
||||
lb1 = int(leftelf[0])
|
||||
ub1 = int(leftelf[1])
|
||||
|
||||
# "C-D"
|
||||
rightelf = twoelves[1].split("-")
|
||||
# ["C", "D"]
|
||||
lb2 = int(rightelf[0])
|
||||
ub2 = int(rightelf[1])
|
||||
|
||||
if ((lb1 <= lb2 and ub1 >= ub2) or # Elf 1 fully covers elf 2
|
||||
(lb2 <= lb1 and ub2 >= ub1)): # Elf 2 fully covers elf 1
|
||||
count += 1
|
||||
print(count)
|
||||
@@ -0,0 +1,11 @@
|
||||
count = 0
|
||||
with open("input.txt", "r") as f:
|
||||
for line in f.readlines():
|
||||
line = line.strip("\n")
|
||||
# Some python magic to split out the strings and convert them to integers
|
||||
pair = [x.split("-") for x in line.split(",")]
|
||||
pair = [[int(y) for y in x] for x in pair]
|
||||
if ((pair[0][0] <= pair[1][0] and pair[0][1] >= pair[1][1]) or
|
||||
(pair[1][0] <= pair[0][0] and pair[1][1] >= pair[0][1])):
|
||||
count += 1
|
||||
print(count)
|
||||
@@ -0,0 +1,26 @@
|
||||
elves = []
|
||||
count = 0
|
||||
|
||||
def inrange(lb, ub, check):
|
||||
"""Returns true iff check is inclusive in-between lb and ub."""
|
||||
return check >= lb and check <= ub
|
||||
|
||||
with open("input.txt", "r") as f:
|
||||
for line in f.readlines():
|
||||
line = line.strip("\n")
|
||||
# Some python magic to split out the strings and convert them to integers
|
||||
pair = [x.split("-") for x in line.split(",")]
|
||||
pair = [[int(y) for y in x] for x in pair]
|
||||
elves.append(pair)
|
||||
# Elves is now a list of list of lists.
|
||||
for elf in elves:
|
||||
lb1 = elf[0][0]
|
||||
lb2 = elf[1][0]
|
||||
ub1 = elf[0][1]
|
||||
ub2 = elf[1][1]
|
||||
if (inrange(lb1, ub1, ub2) or
|
||||
inrange(lb1, ub1, lb2) or
|
||||
inrange(lb2, ub2, ub1) or
|
||||
inrange(lb2, ub2, lb1)):
|
||||
count += 1
|
||||
print(count)
|
||||
Reference in New Issue
Block a user