Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Dictionary solution in Clear category for Follow Instructions by endersprodigy
def follow(instructions):
steps = {'f': 1, 'b': -1, 'l': -1, 'r': 1}
position = (0, 0)
changePosition = list(position)
for i in instructions:
if i == 'l' or i == 'r':
changePosition[0] += steps[i]
elif i == 'f' or i == 'b':
changePosition[1] += steps[i]
return tuple(changePosition)
if __name__ == '__main__':
print("Example:")
print(follow("fflff"))
# These "asserts" are used for self-checking and not for an auto-testing
assert follow("fflff") == (-1, 4)
assert follow("ffrff") == (1, 4)
assert follow("fblr") == (0, 0)
print("Coding complete? Click 'Check' to earn cool rewards!")
July 27, 2020