Багров Дмитрий Андреевич, 620 группа VirtualTurtle 9666 | Максим Попов, 527 группа VirtualTurtle 8714 | ||||
---|---|---|---|---|---|
t | 1 | def turtle(coord, direction): | t | 1 | def turtle(coord, direction): |
2 | x, y = coord | 2 | x, y = coord | ||
3 | dir = direction % 4 | 3 | dir = direction % 4 | ||
4 | cmd = (yield (x, y)) | 4 | cmd = (yield (x, y)) | ||
5 | while True: | 5 | while True: | ||
6 | if cmd == 'f': | 6 | if cmd == 'f': | ||
7 | if dir == 0: | 7 | if dir == 0: | ||
8 | x += 1 | 8 | x += 1 | ||
9 | elif dir == 1: | 9 | elif dir == 1: | ||
10 | y += 1 | 10 | y += 1 | ||
11 | elif dir == 2: | 11 | elif dir == 2: | ||
12 | x -= 1 | 12 | x -= 1 | ||
13 | elif dir == 3: | 13 | elif dir == 3: | ||
14 | y -= 1 | 14 | y -= 1 | ||
15 | elif cmd == 'l': | 15 | elif cmd == 'l': | ||
16 | dir = (dir + 1) % 4 | 16 | dir = (dir + 1) % 4 | ||
17 | elif cmd == 'r': | 17 | elif cmd == 'r': | ||
18 | dir = (dir - 1) % 4 | 18 | dir = (dir - 1) % 4 | ||
19 | cmd = (yield (x, y)) | 19 | cmd = (yield (x, y)) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|