Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
lambda solution in Clear category for Rolling 🎲! by Max0526
from functools import reduce
rolling_dice = lambda moves: reduce(lambda x, move: ({"N": x[1], "S": 7 - x[1], "W": x[2], "E": 7 - x[2]}.get(move),
{"N": 7 - x[0], "S": x[0]}.get(move, x[1]),
{"W": 7 - x[0], "E": x[0]}.get(move, x[2])), moves, (1, 2, 3))[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 3, 2023
Comments: