Skip to content

Instantly share code, notes, and snippets.

@ChrisBeaumont
Created January 26, 2016 06:06
Show Gist options
  • Save ChrisBeaumont/4f96f5ea0d256665bb00 to your computer and use it in GitHub Desktop.
Save ChrisBeaumont/4f96f5ea0d256665bb00 to your computer and use it in GitHub Desktop.
def parse_clues(data):
"""
Traverse a block of wheelscii-encoded puzzles,
yielding each decoded puzzle in ascii
"""
word = []
for pos, char in enumerate(data):
# check for signal character
if char & 0x80:
# the correct ascii value
char = char & ~0x80
word.append(char)
# determine if this is a newline or a clue boundary
if data[pos - 1] & 0x80: # end of clue
yield bytes(word).decode('ascii')
word = []
elif not data[pos + 1] & 0x80: # newline
word.append(ord('\n'))
else:
word.append(char)
if __name__ == "__main__":
rom = open('wheel.nes', 'rb').read()
start, stop = 0x109d0, 0x14618
puzzles = list(parse_clues(rom[start:stop]))
print(puzzles[:5])
# ['WHEEL\nOF\nFORTUNE', 'KINGSTON\nJAMAICA', 'PEKING\nCHINA', 'PLANETARIUM', 'NOME ALASKA']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment