f | def turtle(coord, direction): | f | def turtle(coord, direction): |
n | c = (yield coord) | n | nxt = (yield coord) |
| while c: | | while nxt: |
| if c == 'f': | | if nxt == '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 | if c == 'l': | n | elif nxt == 'l': |
| direction = (direction + 1) % 4 | | direction = (direction + 1) % 4 |
n | if c == 'r': | n | elif nxt == 'r': |
| direction = (direction - 1) % 4 | | direction = (direction - 1) % 4 |
t | c = (yield coord) | t | nxt = (yield coord) |