Skip to content

Instantly share code, notes, and snippets.

@buhii
Created December 14, 2013 02:00
Show Gist options
  • Save buhii/7954757 to your computer and use it in GitHub Desktop.
Save buhii/7954757 to your computer and use it in GitHub Desktop.
Fanta quiz 3
# -*- coding: utf-8 -*-
def all_startswith(question, d):
for num in d:
if question.startswith(num):
yield num
def pickup(string, d, result=[]):
if string == "":
print result, ''.join([d[num] for num in result])
for num in all_startswith(string, d):
tmp = result[:] + [num]
pickup(string[len(num):], d, tmp)
if __name__ == '__main__':
# create num-to-char dictionary
n2c = {}
for i in range(ord('A'), ord('Z') + 1):
n2c[str(i - ord('A') + 1)] = chr(i)
pickup("6114201", n2c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment