Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
if-elif solution in Speedy category for Follow Instructions by rockwellshabani
def follow(instructions: str) -> tuple[int, int] | list[int]:
x, y = 0, 0
for i in instructions:
if i == "f":
y += 1
elif i == "b":
y -= 1
elif i == "r":
x += 1
else:
x -=1
return x, y
print("Example:")
print(list(follow("fflff")))
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!")
Jan. 15, 2023
Comments: