Skip to content

Instantly share code, notes, and snippets.

@wiomoc
Last active December 21, 2020 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wiomoc/aa4dfec97ef3a8cd7e490aab9e3dbfdc to your computer and use it in GitHub Desktop.
Save wiomoc/aa4dfec97ef3a8cd7e490aab9e3dbfdc to your computer and use it in GitHub Desktop.
code_matrix = [
[0x1c, 0xbd, 0x55, 0xe9, 0x55],
[0x1c, 0xbd, 0x1c, 0x55, 0xe9],
[0x55, 0xe9, 0xe9, 0xbd, 0xbd],
[0x55, 0xff, 0xff, 0x1c, 0x1c],
[0xff, 0xe9, 0x1c, 0xbd, 0xff]
]
sequences = [
[0x1c, 0x1c, 0x55],
[0X55, 0Xff, 0X1c],
[0xbd, 0xe9, 0xbd, 0x55],
[0x55, 0x1c, 0xff, 0xbd]
]
buffer_size = 9
sequences = ["".join([hex(c) for c in seq]) for seq in sequences]
def gen_path(current_path, horizontal):
if len(current_path) == buffer_size:
yield (current_path, "".join([hex(code_matrix[pos[0]][pos[1]]) for pos in current_path]))
else:
current_pos = current_path[-1]
if horizontal:
options = ((x, current_pos[1]) for x in range(len(code_matrix)))
else:
options = ((current_pos[0], y) for y in range(len(code_matrix)))
for option in options:
if option not in current_path:
yield from gen_path(current_path + [option], not horizontal)
paths = gen_path([(0, 0)], True)
def score(path):
return sum((1 for s in sequences if path[1].find(s) != -1))
print(max(paths, key=score))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment