Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
When no switch Use Func_Ptr solution in Clear category for Follow Instructions by Lumy
f = lambda x: (x[0] + 0, x[1] + 1)
l = lambda x: (-1 + x[0], 0 + x[1])
r = lambda x: (x[0] + 1, x[1] + 0)
b = lambda x: (0+x[0], x[1] -1)
def follow(instructions):
p = (0, 0)
pf = {'f':f, 'l':l, 'r':r, 'b':b}
for i in instructions:
p = pf[i](p)
return p
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!")
Nov. 27, 2020
Comments: