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