Skip to content

Instantly share code, notes, and snippets.

@zbyte64
Created December 9, 2013 23:20
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 zbyte64/7882934 to your computer and use it in GitHub Desktop.
Save zbyte64/7882934 to your computer and use it in GitHub Desktop.
import io
numbers = {
(' _ ', '| |', '|_|'): 0,
(' ', ' |', ' |'): 1,
(' _ ', ' _|', '|_ '): 2,
(' _ ', ' _|', ' _|'): 3,
(' ', '|_|', ' |'): 4,
(' _ ', '|_ ', ' _|'): 5,
(' _ ', '|_ ', '|_|'): 6,
(' _ ', ' |', ' |'): 7,
(' _ ', '|_|', '|_|'): 8,
(' _ ', '|_|', ' _|'): 9,
}
def parsenumber(tpl):
return numbers[tpl]
def readtuples(msg):
top, mid, btm = msg.readline(), msg.readline(), msg.readline()
print top
print mid
print btm
for i in range(0, len(top), 3):
if i+3 > len(top): break
if i+3 > len(mid): break
if i+3 > len(btm): break
yield (top[i:i+3], mid[i:i+3], btm[i:i+3])
sample = \
' _ _ _ _ _ _ _ \n' + \
' | _| _||_||_ |_ ||_||_|\n' + \
' ||_ _| | _||_| ||_| _|\n'
def test():
infile = io.BytesIO(sample)
for tpl in readtuples(infile):
print parsenumber(tpl)
if __name__ == "__main__":
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment