Бубнов Максим, 514 группа VirtualTurtle 8959 | Арсен Жуматай,304 VirtualTurtle 9422 | ||||
---|---|---|---|---|---|
n | 1 | def turtle(coord, dir): | n | 1 | def turtle(coord, direction): |
2 | x, y = coord | 2 | x, y = coord | ||
3 | dirs = [(1, 0), (0, 1), (-1, 0), (0, -1)] | 3 | dirs = [(1, 0), (0, 1), (-1, 0), (0, -1)] | ||
4 | while True: | 4 | while True: | ||
5 | command = (yield (x, y)) | 5 | command = (yield (x, y)) | ||
6 | if command == 'f': | 6 | if command == 'f': | ||
n | 7 | dx, dy = dirs[dir] | n | 7 | dx, dy = dirs[direction] |
8 | x, y = (x + dx, y + dy) | 8 | x, y = (x + dx, y + dy) | ||
9 | elif command == 'l': | 9 | elif command == 'l': | ||
n | 10 | dir = (dir + 1) % 4 | n | 10 | direction = (direction + 1) % 4 |
11 | elif command == 'r': | 11 | elif command == 'r': | ||
t | 12 | dir = (dir - 1) % 4 | t | 12 | direction = (direction - 1) % 4 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|