'''
https://[Log in to view URL]
https://[Log in to view URL]
(FRENCH) https://[Log in to view URL]
'''
from fractions import Fraction
import numpy as np
np.set_printoptions(precision=20)
n = 5
arr = [[0 for _ in range(n**2)] for _ in range(n**2)]
for x in range(n):
for y in range(n):
idx = x * n + y
for dx, dy in ((1, 0), (-1, 0), (0, -1), (0, 1)):
u, v = x + dx, y + dy
if 0 <= u < n and 0 <= v < n:
p = u * n + v
arr[idx][p] = 1 / 4
# for r in arr:
# print(r)
array = np.identity(n**2) - np.array(arr)
# print(np.linalg.det(array))
res = np.linalg.inv(array) @ np.ones((n**2, 1))
print(res[n**2//2][0])
To embed this program on your website, copy the following code and paste it into your website's HTML: