Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Follow Instructions by poa
def move(pos: list[int, int], direction: str = "f") -> None:
if direction == "f":
pos[:] = [pos[0], pos[1] + 1]
if direction == "b":
pos[:] = [pos[0], pos[1] - 1]
if direction == "l":
pos[:] = [pos[0] - 1, pos[1]]
if direction == "r":
pos[:] = [pos[0] + 1, pos[1]]
return None
def follow(instructions: str) -> tuple[int, int] | list[int]:
pos = [0, 0]
for d in instructions:
move(pos, d)
return pos
print("Example:")
print(list(follow("fflff")))
# These "asserts" are used for self-checking
assert list(follow("fflff")) == [-1, 4]
assert list(follow("ffrff")) == [1, 4]
assert list(follow("fblr")) == [0, 0]
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 7, 2024
Comments: