Day 12 (split line to (cmd, num))
This commit is contained in:
@@ -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)))
|
||||
|
||||
@@ -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)))
|
||||
|
||||
Reference in New Issue
Block a user