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