Skip to content

Instantly share code, notes, and snippets.

Created May 29, 2016 20:13
Show Gist options
  • Save anonymous/474fe84988b3f208f60cce0fba93a417 to your computer and use it in GitHub Desktop.
Save anonymous/474fe84988b3f208f60cce0fba93a417 to your computer and use it in GitHub Desktop.
Checks that the encoding described in the page bellow is resilient to rotations. https://github.com/polyvision/EasyRaceLapTimer/blob/master/docs/ir_pulses.md
def encode(n):
if (n > 63) | (n < 0):
raise Exception('Out of range {0}'.format(n))
ret = [digit for digit in bin(n)[2:]] # [2:] to chop off the "0b" part
ret += [reduce(lambda a,b: '1' if (a != b) else '0', ret)]
return ''.join(['0'] * (9 - len(ret)) + ret)
def rotate(l,n):
return l[n:] + l[:n]
legal = frozenset(map(encode, range(0,63)))
for x in legal:
for rot in range(1,8):
if rotate(x, rot) in legal:
print 'Found that {0} in rotation {1} is equal to {2}'.format(x, rot, rotate(x, rot))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment