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