f | def turtle(coord, direction): | f | def turtle(coord, direction): |
| x, y = coord | | x, y = coord |
| while True: | | while True: |
n | cmd = (yield (x, y)) | n | command = (yield (x, y)) |
| if cmd == 'f': | | if command == 'f': |
| if direction == 0: | | if direction == 0: |
| x += 1 | | x += 1 |
| elif direction == 1: | | elif direction == 1: |
| y += 1 | | y += 1 |
| elif direction == 2: | | elif direction == 2: |
| x -= 1 | | x -= 1 |
| elif direction == 3: | | elif direction == 3: |
| y -= 1 | | y -= 1 |
n | elif cmd == 'l': | n | elif command == 'l': |
| direction = (direction + 1) % 4 | | direction = (direction + 1) % 4 |
t | elif cmd == 'r': | t | elif command == 'r': |
| direction = (direction - 1) % 4 | | direction = (direction - 1) % 4 |