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