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