Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python towers of hanoi recursive

# Python towers of hanoi recursive
def hanoiArray(n):

    def move(n, start=1, end=3):
        if n > 0:
            ans.append(move(n-1, start, 6 - start - end))
            pegs[end-1].append(pegs[start-1].pop())
            move(n-1, 6 - start - end, end)
        return str(pegs)

    ans, pegs = [], [list(range(n, 0, -1)), [], []]
    ans.append(move(n))
    return '
'.join(ans)
Comment

PREVIOUS NEXT
Code Example
Python :: read csv python 
Python :: comtypes python 
Python :: argparse print help if no arguments 
Python :: pyspark read from redshift 
Python :: conv2 python 
Python :: missing data in python 
Python :: scikit learn to identify highly correlated features 
Python :: how to check a string is empty in python 
Python :: python create random mac 
Python :: how to check if string is in byte formate pythin 
Python :: matrix diagonal sum leetcode 
Python :: how to comment text in python 
Python :: django change settings at runtime 
Python :: how to find length of list python 
Python :: how to get the length of a string in python 
Python :: binary to decimal in python without inbuilt function 
Python :: python t test 
Python :: keras conv2d 
Python :: ImportError: cannot import name include 
Python :: how to improve accuracy of random forest classifier 
Python :: convert dictionary keys to list python 
Python :: python encode file 
Python :: doc strings python 
Python :: python remove a character from a string 
Python :: inpuit inf terfminal ppython 
Python :: lucky number codechef solution 
Python :: pandas dataframe caption 
Python :: array creation in numpy 
Python :: standard deviation in python numpy 
Python :: how to use sort in python 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =