This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

pattern calculator

By: liucijus on Nov 27th, 2012  |  syntax: Python  |  size: 0.38 KB  |  views: 35  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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
clone this paste RAW Paste Data