f | def turtle(coord, direction): | f | def turtle(coord, direction): |
n | val = (yield coord) | n | trl = (yield coord) |
| while val: | | while trl: |
| if val == 'f': | | if trl == '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]) |
| else: | | else: |
| coord = (coord[0], coord[1] - 1) | | coord = (coord[0], coord[1] - 1) |
n | | n | elif trl == 'r': |
| | | direction = (direction + 3) % 4 |
| elif val == 'l': | | elif trl == 'l': |
| direction = (direction + 1) % 4 | | direction = (direction + 1) % 4 |
t | elif val == 'r': | t | |
| direction = (direction + 3) % 4 | | |
| val = (yield coord) | | trl = (yield coord) |