Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Deque solution solution in Clear category for Rolling 🎲! by Nocturne13
from collections import deque
def rolling_dice(moves: str) -> int:
# your code here
S_to_N = deque([1, 5, 6, 2])
E_to_W = deque([1, 3, 6, 4])
for i in moves:
if i == "N":
E_to_W[0] = S_to_N[-1]
E_to_W[2] = S_to_N[1]
S_to_N.rotate(1)
elif i == "S":
E_to_W[0] = S_to_N[1]
E_to_W[2] = S_to_N[-1]
S_to_N.rotate(-1)
elif i == "E":
S_to_N[0] = E_to_W[-1]
S_to_N[2] = E_to_W[1]
E_to_W.rotate(1)
elif i == "W":
S_to_N[0] = E_to_W[1]
S_to_N[2] = E_to_W[-1]
E_to_W.rotate(-1)
return S_to_N[0]
print("Example:")
print(rolling_dice("SE"))
# These "asserts" are used for self-checking
assert rolling_dice("SN") == 1
assert rolling_dice("") == 1
assert rolling_dice("EESWN") == 6
assert rolling_dice("NWSNWEESNW") == 3
assert rolling_dice("NNNSESNESWNENSWNNWSWNSSNWWSWNW") == 5
print("The mission is done! Click 'Check Solution' to earn rewards!")
May 11, 2023