#1. We need a helper function, `fib_tail` to keep track of the variables we update in the while loop. (lines 4-5 in iterative)
#2-3. Return `curr` when the opposite of the while condition is met. (lines 3,6 in iterative)
#4. Recursively call `fib_tail`, using same update logic as while loop body when passing arguments. (line 5 in iterative)
#5. Call helper function with initial values for the additional variables (line 1 in iterative)
* We're going to pretend that Python supports tail recursion. It doesn't, but I figure more people are familiar with python; think of it more as pseudocode for instruction. You could easily implement the above in something like Scheme
Python iterative solution
Python tail-recursive solution* Some explanation of the 1-1 conversion process:#1. We need a helper function, `fib_tail` to keep track of the variables we update in the while loop. (lines 4-5 in iterative)
#2-3. Return `curr` when the opposite of the while condition is met. (lines 3,6 in iterative)
#4. Recursively call `fib_tail`, using same update logic as while loop body when passing arguments. (line 5 in iterative)
#5. Call helper function with initial values for the additional variables (line 1 in iterative)
* We're going to pretend that Python supports tail recursion. It doesn't, but I figure more people are familiar with python; think of it more as pseudocode for instruction. You could easily implement the above in something like Scheme