SHARE
TWEET

pattern calculator

liucijus Nov 27th, 2012 36 Never
  1. def createPatternDictionary(pattern):
  2.     rules = {1: ('...', '.'), 2: ('..x', '.'), 4: ('.x.', '.'), 8: ('.xx', '.'),
  3.              16: ('x..', '.'), 32: ('x.x', '.'), 64: ('xx.', '.'), 128: ('xxx', '.')}
  4.     left = pattern
  5.     for i in sorted(rules.keys(), reverse=True):
  6.         if left - i >= 0:
  7.             left = left - i
  8.             rules[i] = rules[i][0], 'x'
  9.     return rules
RAW Paste Data
Top