import itertoolsdim = 100m = list(range(1, dim+1))w = list(range(-1, -dim-1, -1))num = 0global zero_numzero_num = 0m_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 breakprint(zero_num)print(num)print((num-zero_num)/num)
As dim goes to infinity, the final ratio should be approaching to 1/e.