from __future__ import division
import itertools as it
import numpy as np
l = input('How many lattices?_')
m = input('How many markers?_')
sums = 0
sumcount = 0
pos = 1
neg = -1
L = it.product([-1,1], repeat =l)
M = range(0,l)
markers = it.combinations(M, m)
k = 0
for ring in L:
for marker in markers:
while k < 2*len(ring):
ring = list(np.roll(ring,1))
for x in marker:
t = ring.pop(x)
if t < 0:
ring.insert(x,pos)
elif t > 0:
ring.insert(x,neg)
else:
print('This is why we cant have nice things...')
sums = sums + abs(sum(ring))
sumcount = sumcount + 1
k = k + 1
k = 0
k = 0
print 'Average deviation: ', sums/sumcount