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