Day 12 (split line to (cmd, num))

This commit is contained in:
Sebastian Seedorf
2020-12-12 12:08:50 +01:00
parent 500bc23447
commit f8abb73ad2
2 changed files with 12 additions and 12 deletions

View File

@@ -5,13 +5,13 @@ drctn = 1
targets = [1j, 1, -1j, -1]
target_str = "NESW"
for line in lines:
if line[0] in target_str:
pos += targets[target_str.index(line[0])] * line[1]
elif line[0] in "LR":
times = (-line[1] if line[0] == "R" else line[1]) / 90
for cmd, num in lines:
if cmd in target_str:
pos += targets[target_str.index(cmd)] * num
elif cmd in "LR":
times = (-1 if cmd == "R" else 1) * num / 90
drctn = drctn * 1j ** times
else:
pos += drctn * line[1]
pos += drctn * num
print(int(abs(pos.real) + abs(pos.imag)))

View File

@@ -5,13 +5,13 @@ drctn = 10+1j
targets = [1j, 1, -1j, -1]
target_str = "NESW"
for line in lines:
if line[0] in target_str:
drctn += targets[target_str.index(line[0])] * line[1]
elif line[0] in "LR":
times = (-line[1] if line[0] == "R" else line[1]) / 90
for cmd, num in lines:
if cmd in target_str:
drctn += targets[target_str.index(cmd)] * num
elif cmd in "LR":
times = (-1 if cmd == "R" else 1) * num / 90
drctn = drctn * 1j ** times
else:
pos += drctn * line[1]
pos += drctn * num
print(int(abs(pos.real) + abs(pos.imag)))