Код: Выделить всё
0 1 2
3 4 5
6 7 8
Код: Выделить всё
def coords(number):
y, x = divmod(number, 3)
return x, y
def draw_arrow(i, j):
x1, y1 = coords(i)
x2, y2 = coords(j)
dx = x2 - x1
dy = y2 - y1
plt.arrow(x1, y1, dx, dy,
head_width = 0.04,
width = 0.01,
ec ='green')
def draw(path):
# By default, the input is a length 9 tuple
plt.clf()
for i in range(0,3):
for j in range(0,3):
plt.scatter(i, j, s=200, c='black', edgecolors='black')
plt.ylim(2.1, -0.1)
for i in range(len(path)-1):
draw_arrow(path[i], path[i+1])
plt.show()
Код: Выделить всё
draw((2, 7, 5, 0, 3, 6, 4, 8, 1))
Код: Выделить всё
draw((0, 4, 6, 3, 7, 2, 5, 8, 1))

Как подсчитать пересечения в таком коде пролистывания?
Подробнее здесь: https://stackoverflow.com/questions/798 ... swipe-code