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.
50 lines
1.2 KiB
50 lines
1.2 KiB
import ast
|
|
|
|
lines = open("input.txt", "r").read().splitlines()
|
|
|
|
|
|
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
|
|
|
|
|
|
ordered = []
|
|
lines.append("[[2]]")
|
|
lines.append("[[6]]")
|
|
for line in lines:
|
|
if line == "":
|
|
continue
|
|
ordered.append(ast.literal_eval(line))
|
|
|
|
sorted = False
|
|
while not sorted:
|
|
sorted = True
|
|
for i in range(len(ordered) - 1):
|
|
if not resolve(ordered[i], ordered[i + 1]):
|
|
hold = ordered[i]
|
|
ordered[i] = ordered[i + 1]
|
|
ordered[i + 1] = hold
|
|
sorted = False
|
|
|
|
signals = []
|
|
for idx, o in enumerate(ordered):
|
|
if str(o) == "[[2]]" or str(o) == "[[6]]":
|
|
signals.append(idx + 1)
|
|
|
|
print(signals)
|
|
print(signals[0] * signals[1])
|