Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 27th, 2013  |  syntax: Python  |  size: 0.86 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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 = it.product([-1,1], repeat =l)
  11. M = range(0,l)
  12. markers = it.combinations(M, m)
  13. k = 0
  14. for ring in L:
  15.     for marker in markers:
  16.         while k < 2*len(ring):
  17.             ring = list(np.roll(ring,1))
  18.             for x in marker:
  19.                 t = ring.pop(x)
  20.                 if t < 0:
  21.                     ring.insert(x,pos)
  22.                 elif t > 0:
  23.                     ring.insert(x,neg)
  24.                 else:
  25.                     print('This is why we cant have nice things...')
  26.                 sums = sums + abs(sum(ring))
  27.                 sumcount = sumcount + 1
  28.                 k = k + 1
  29.         k = 0
  30.     k = 0
  31.          
  32. print 'Average deviation: ', sums/sumcount