Advertisement
Guest User

My Code

a guest
Feb 26th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from __future__ import division
  2. import itertools as it
  3. import numpy as np
  4. l = input('How many lattices?_')
  5. m = input('How many markers?_')
  6. sums = 0
  7. sumcount = 0
  8. pos = 1
  9. neg = -1
  10. L = list(it.product([-1,1], repeat =l))
  11. M = range(0,l) # makes a list from 0 to l-1, giving l entries, starting with 0 just like the indices of the lattices.
  12. Markers = list(it.combinations(M, m))
  13. i = 0
  14. j = 0
  15. k = 0
  16. while i < len(L):
  17.     Ring = L[i]
  18.     while j < len(Markers):
  19.         while k < 2*len(Ring):
  20.             Marker = Markers[j]
  21.             Ring = list(np.roll(Ring,1))
  22.             for x in Marker:
  23.                 t = Ring.pop(x)
  24.                 if t < 0:
  25.                     Ring.insert(x,pos)
  26.                 elif t > 0:
  27.                     Ring.insert(x,neg)
  28.                 else:
  29.                     print('This is why we cant have nice things...')
  30.             sums = sums + abs(sum(Ring))
  31.             sumcount = sumcount + 1
  32.             k = k + 1
  33.         j = j + 1
  34.         k = 0
  35.     i = i + 1
  36.     j = 0
  37.     k = 0
  38.          
  39. print 'Average deviation: ', sums/sumcount
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement