Created
May 3, 2020 15:33
-
-
Save martin-ueding/8f8d18f445ce056bea114d0df81c4bc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
# Copyright © 2016 Martin Ueding <mu@martin-ueding.de> | |
import argparse | |
stacks = [ | |
[4, 3, 2, 1], | |
[], | |
[], | |
] | |
def move(from_stack, to_stack, items): | |
if items == 1: | |
item = stacks[from_stack].pop() | |
stacks[to_stack].append(item) | |
print_stacks() | |
else: | |
temp = other(from_stack, to_stack) | |
move(from_stack, temp, items - 1) | |
move(from_stack, to_stack, 1) | |
move(temp, to_stack, items - 1) | |
def other(a, b): | |
options = set([0, 1, 2]) - set([a, b]) | |
return list(options)[0] | |
def print_stacks(): | |
for stack in stacks: | |
print('|', ' '.join(map(str, stack))) | |
print() | |
def main(): | |
options = _parse_args() | |
print_stacks() | |
move(0, 2, len(stacks[0])) | |
def _parse_args(): | |
''' | |
Parses the command line arguments. | |
:return: Namespace with arguments. | |
:rtype: Namespace | |
''' | |
parser = argparse.ArgumentParser(description='') | |
options = parser.parse_args() | |
return options | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment