Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Rolling 🎲! by mortonfox
MOVE = {
'N': (4, 0, 2, 3, 5, 1),
'S': (1, 5, 2, 3, 0, 4),
'E': (2, 1, 5, 0, 4, 3),
'W': (3, 1, 0, 5, 4, 2)
}
def rolling_dice(moves: str) -> int:
dice = [1, 5, 4, 3, 2, 6]
for move in moves: dice = [dice[i] for i in MOVE[move]]
return dice[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 4, 2023
Comments: