Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
An object-oriented Approach III solution in Clear category for Follow Instructions by WreakHavoc
class Piece:
moves = {'f': (0, 1), 'b': (0, -1), 'l': (-1, 0), 'r': (1, 0)}
def __init__(self):
self.x = 0
self.y = 0
@property
def coords(self):
return self.x, self.y
def move(self, instructions):
for movement in instructions:
self.x += self.moves[movement][0]
self.y += self.moves[movement][1]
def follow(instructions):
pawn = Piece()
pawn.move(instructions)
return pawn.coords
July 3, 2020