Recursive

Run Settings
LanguagePython
Language Version
Run Command
def fib(n): if n == 1 or n == 2: return n else: return fib( n - 1) + fib( n -2) print(fib(6)) A = [3,2,1] B = [] C = [] def move(n, source, target, auxiliary): if n > 0: # move n-1 disks from source to auxiliary, so they are out of the way move(n-1, source, auxiliary, target) # move the nth disk from source to target if( len(source) > 0): target.append(source.pop()) # Display our progress print(A, B, C, '##############', sep='\n') # move the n-1 disks that we left on auxiliary onto target move(n-1, auxiliary, target, source) # initiate call from source A to target C with auxiliary B move(len(A), A, C, B)
Editor Settings
Theme
Key bindings
Full width
Lines