• API
• FAQ
• Tools
• Trends
• Archive
SHARE
TWEET

# Code 2 the codening

a guest Feb 27th, 2013 9 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 = it.product([-1,1], repeat =l)
11. M = range(0,l)
12. markers = list(it.combinations(M, m))
13. j = 0
14. k = 0
15. for ring in L:
16.     while j < len(markers):
17.         while k < 2*len(ring):
18.             marker = markers[j]
19.             ring = list(np.roll(ring,1))
20.             for x in marker:
21.                 t = ring.pop(x)
22.                 if t < 0:
23.                     ring.insert(x,pos)
24.                 elif t > 0:
25.                     ring.insert(x,neg)
26.                 else:
27.                     print('This is why we cant have nice things...')
28.             sums = sums + abs(sum(ring))
29.             sumcount = sumcount + 1
30.             k = k + 1
31.         j = j + 1
32.         k = 0
33.     j = 0
34.     k = 0
35.
36. print 'Average deviation: ', sums/sumcount
RAW Paste Data
Top