Skip to content

Instantly share code, notes, and snippets.

@kratsg
Created December 11, 2014 05:35
Show Gist options
  • Save kratsg/d311a9f6b8d6a4af1201 to your computer and use it in GitHub Desktop.
Save kratsg/d311a9f6b8d6a4af1201 to your computer and use it in GitHub Desktop.
Decode lights over all possible combinations for hex?
lights = [['g','r'],
['y','d'],
['r','r'],
['b','d'],
['g','r'],
['b','r'],
['y','d'],
['p','d'],
['b','d'],
['r','d'],
['b','r']]
def encoder(items, key, reverse=False):
green, yellow, red, blue, purple, right, down = key
translateColors = {'g': green, 'y': yellow, 'r': red, 'b': blue, 'p': purple}
translatePositions = {'d': down, 'r': right}
color, position = items
color = translateColors[color]
position = translatePositions[position]
if reverse:
return ('%s%s' % (position, color)).decode('hex')
else:
return ('%s%s' % (color, position)).decode('hex')
from itertools import combinations
hexList = '0123456789abcdef'
for colors in combinations(hexList, 5):
for directions in combinations(hexList, 2):
print colors+directions
print "\t", ''.join([encoder(light, colors+directions) for light in lights])
print "\t", '-'*20
print "\t", ''.join([encoder(light, colors+directions, reverse=True) for light in lights])
print '.'*30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment