START = 11
TARGET = 25
def main():
queue = [(START, [str(START)])]
while queue:
curr, path = queue.pop(0)
if curr == TARGET:
return path
queue.append((curr * 2, path + ['x2 => %s' % (curr * 2)]))
queue.append((curr - 3, path + ['-3 => %s' % (curr - 3)]))
assert False, 'Expect never to reach here'
if __name__ == "__main__":
path = main()
print '\n'.join(path)
2 Responses
Write a comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.