quiz_3_this_year

quiz_3.pdf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def explore_this_way(directions):
symbols = {
'black_circle': 9899,
'white_square': 11036,
'red_circle': 128308,
'blue_circle': 128309,
'orange_square': 128999,
'yellow_square': 129000,
'green_square': 129001,
'purple_square': 129002,
'brown_square': 129003
}
direction_dict = {
'⬆': (0, 1),
'➡': (1, 0),
'⬇': (0, -1),
'⬅': (-1, 0)
}
x, y = 0, 0
start_x, start_y = x, y
boundaries = [0, 0, 0, 0]
visited_count = {(x, y): 1}

for direction in directions:
if direction in direction_dict:
increment = direction_dict[direction]
x += increment[0]
y += increment[1]
visited_count[(x, y)] = visited_count.get((x, y), 0) + 1
boundaries = [min(boundaries[0], x), max(boundaries[1], x), min(boundaries[2], y), max(boundaries[3], y)]

grid = [[' ' for _ in range(boundaries[1] - boundaries[0] + 1)] for _ in range(boundaries[3] - boundaries[2] + 1)]

for (px, py), visits in visited_count.items():
dy = py - boundaries[2]
dx = px - boundaries[0]
if visits % 5 == 1:
grid[dy][dx] = 'yellow_square'
elif visits % 5 == 2:
grid[dy][dx] = 'orange_square'
elif visits % 5 == 3:
grid[dy][dx] = 'brown_square'
elif visits % 5 == 4:
grid[dy][dx] = 'green_square'
elif visits % 5 == 0:
grid[dy][dx] = 'purple_square'
elif visits >= 6:
grid[dy][dx] = 'black_circle'

grid[start_y - boundaries[2]][start_x - boundaries[0]] = 'blue_circle'
grid[y - boundaries[2]][x - boundaries[0]] = 'red_circle'

if y == start_y and x == start_x:
grid[y - boundaries[2]][x - boundaries[0]] = 'black_circle'

for row in grid[::-1]:
for element in row:
if element == ' ':
print(chr(symbols['white_square']), end='')
else:
print(chr(symbols[element]), end='')
print()


if __name__ == "__main__":
directions = "➡➡⬇⬅⬆⬆⬅⬇➡➡⬅⬅⬅➡➡➡⬅⬆⬆➡"
explore_this_way(directions)
# ⬜⬜🟨🔴
# ⬜🟨🟧⬜
# 🟨🔵🟨🟫
# ⬜⬜🟨🟨