f | def turtle(coord, direction): | f | def turtle(coord, direction): |
n | step = yield coord | n | command = yield coord |
| while step: | | while True: |
| if step == 'f': | | # 0 — восток, 1 — север, 2 — запад, 3 — юг |
| | | if command == "f": |
| if direction == 0: | | if direction == 0: |
| coord = (coord[0] + 1, coord[1]) | | coord = (coord[0] + 1, coord[1]) |
| elif direction == 1: | | elif direction == 1: |
| coord = (coord[0], coord[1] + 1) | | coord = (coord[0], coord[1] + 1) |
| elif direction == 2: | | elif direction == 2: |
| coord = (coord[0] - 1, coord[1]) | | coord = (coord[0] - 1, coord[1]) |
| else: | | else: |
| coord = (coord[0], coord[1] - 1) | | coord = (coord[0], coord[1] - 1) |
n | elif step == 'l': | n | elif command == "l": |
| direction = (direction + 1) % 4 | | direction = (direction + 1) % 4 |
| else: | | else: |
| direction = (direction + 3) % 4 | | direction = (direction + 3) % 4 |
t | step = yield coord | t | command = yield coord |
| | | |