Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

pattern calculator

By: liucijus on Nov 27th, 2012  |  syntax: Python  |  size: 0.38 KB  |  hits: 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