f | def turtle(coord, direction): | f | def turtle(coord, direction): |
n | turn = (yield) | n | move = (yield coord) |
| while True: | | while True: |
n | if turn == 'f': | n | if move == 'f': |
| if direction == 0: | | if direction == 0: |
| coord = (coord[0] + 1, coord[1]) | | coord = (coord[0] + 1, coord[1]) |
n | if direction == 1: | n | elif direction == 1: |
| coord = (coord[0], coord[1] + 1) | | coord = (coord[0], coord[1] + 1) |
n | if direction == 2: | n | elif direction == 2: |
| coord = (coord[0] - 1, coord[1]) | | coord = (coord[0] - 1, coord[1]) |
n | if direction == 3: | n | elif direction == 3: |
| coord = (coord[0], coord[1] - 1) | | coord = (coord[0], coord[1] - 1) |
n | | n | if move == 'l': |
| | | direction = (direction + 1) % 4 |
| if turn == 'r': | | if move == 'r': |
| direction = (direction - 1) % 4 | | direction = (direction - 1) % 4 |
t | if turn == 'l': | t | |
| direction = (direction + 1) % 4 | | |
| turn = (yield coord) | | move = (yield coord) |