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