Vertification of an assignment from Stochastic Processing. Using Brute Force and "itertools" library.
import itertools dim = 100 m = list(range(1, dim+1)) w = list(range(-1, -dim-1, -1)) num = 0 global zero_num zero_num = 0 m_all = list(itertools.permutations(m,dim)) w_all = list(itertools.permutations(w,dim)) num = len(m_all) * len(w_all) for m in m_all: for w in w_all: for i in range(dim): if m[i] + w[i] == 0: zero_num += 1 break print(zero_num) print(num) print((num-zero_num)/num)
As dim goes to infinity, the final ratio should be approaching to 1/e.