Day 12 (split line to (cmd, num))
This commit is contained in:
@@ -5,13 +5,13 @@ drctn = 1
|
|||||||
targets = [1j, 1, -1j, -1]
|
targets = [1j, 1, -1j, -1]
|
||||||
target_str = "NESW"
|
target_str = "NESW"
|
||||||
|
|
||||||
for line in lines:
|
for cmd, num in lines:
|
||||||
if line[0] in target_str:
|
if cmd in target_str:
|
||||||
pos += targets[target_str.index(line[0])] * line[1]
|
pos += targets[target_str.index(cmd)] * num
|
||||||
elif line[0] in "LR":
|
elif cmd in "LR":
|
||||||
times = (-line[1] if line[0] == "R" else line[1]) / 90
|
times = (-1 if cmd == "R" else 1) * num / 90
|
||||||
drctn = drctn * 1j ** times
|
drctn = drctn * 1j ** times
|
||||||
else:
|
else:
|
||||||
pos += drctn * line[1]
|
pos += drctn * num
|
||||||
|
|
||||||
print(int(abs(pos.real) + abs(pos.imag)))
|
print(int(abs(pos.real) + abs(pos.imag)))
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ drctn = 10+1j
|
|||||||
targets = [1j, 1, -1j, -1]
|
targets = [1j, 1, -1j, -1]
|
||||||
target_str = "NESW"
|
target_str = "NESW"
|
||||||
|
|
||||||
for line in lines:
|
for cmd, num in lines:
|
||||||
if line[0] in target_str:
|
if cmd in target_str:
|
||||||
drctn += targets[target_str.index(line[0])] * line[1]
|
drctn += targets[target_str.index(cmd)] * num
|
||||||
elif line[0] in "LR":
|
elif cmd in "LR":
|
||||||
times = (-line[1] if line[0] == "R" else line[1]) / 90
|
times = (-1 if cmd == "R" else 1) * num / 90
|
||||||
drctn = drctn * 1j ** times
|
drctn = drctn * 1j ** times
|
||||||
else:
|
else:
|
||||||
pos += drctn * line[1]
|
pos += drctn * num
|
||||||
|
|
||||||
print(int(abs(pos.real) + abs(pos.imag)))
|
print(int(abs(pos.real) + abs(pos.imag)))
|
||||||
|
|||||||
Reference in New Issue
Block a user