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