You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
953 B
41 lines
953 B
import ast
|
|
|
|
lines = open("input.txt", "r").read().splitlines()
|
|
|
|
order = []
|
|
|
|
|
|
def resolve(left, right):
|
|
if isinstance(left, int) and isinstance(right, list):
|
|
return resolve([left], right)
|
|
if isinstance(left, list) and isinstance(right, int):
|
|
return resolve(left, [right])
|
|
if isinstance(left, list) and isinstance(right, list):
|
|
for x, y in zip(left, right):
|
|
resolved = resolve(x, y)
|
|
if resolved is not None:
|
|
return resolved
|
|
return resolve(len(left), len(right))
|
|
if left < right:
|
|
return True
|
|
elif left > right:
|
|
return False
|
|
else:
|
|
return None
|
|
|
|
|
|
counter = 0
|
|
for i in range(0, len(lines), 3):
|
|
left = lines[i + 0]
|
|
right = lines[i + 1]
|
|
counter += 1
|
|
left = ast.literal_eval(left)
|
|
right = ast.literal_eval(right)
|
|
|
|
right_order = resolve(left, right)
|
|
|
|
if right_order:
|
|
order.append(counter)
|
|
|
|
print(sum(order))
|