f | def turtle(coord, direction): | f | def turtle(coord, direction): |
n | mas = [(1, 0), (0, 1), (-1, 0), (0, -1)] | n | directions = [(1, 0), (0, 1), (-1, 0), (0, -1)] |
| x, y = coord | | x, y = coord |
| while True: | | while True: |
n | pos = (yield (x, y)) | n | command = (yield (x, y)) |
| if pos == 'f': | | if command == 'f': |
| dx, dy = mas[direction] | | dx, dy = directions[direction] |
| x += dx | | x += dx |
| y += dy | | y += dy |
n | elif pos == 'l': | n | elif command == 'l': |
| direction = (direction + 1) % 4 | | direction = (direction + 1) % 4 |
t | elif pos == 'r': | t | elif command == 'r': |
| direction = (direction - 1) % 4 | | direction = (direction - 1) % 4 |