Go Recursion – The Tower Of Hanoi

If you want to know the logic of the tower of Hanoi, please refer to this article Python recursion – The Tower of Hanoi. They are exactly the same, just using different language.

Continue reading

Advertisements

Python recursion – The Tower of Hanoi

I don’t have problem with recursion, but I did have problem with understanding the logic of the tower of Hanoi before. My husband even tried to explain the logic to me when he got a bad cold, but my brain was just like sticking in some place and couldn’t understand why.

But the logic is super simple when I finally figured it out.
Continue reading

Python and simple recursion

This afternoon my husband and I talked about recursion, and we decided to write some recursion functions with different languages. He uses JavaScript, and I use Python.

Here is the simple question: Please use recursion to revert 12345 to 54321

def reverse(val, new_val):
    if val == '':
        print(new_val)
    else:
        reverse(val[:-1], new_val + val[-1:])

if __name__ == '__main__':
    reverse(raw_input('Please provide any number: '), '')

Continue reading