Solving The Steps Algorithm Problem Part 2

For this blog, I’ll be going over another solution that solves the steps problem. Last week, I wrote a blog on how to solve this problem. Be sure to check out the resources section at the bottom of this blog!

As a reminder of what we’re trying to solve, here’s a screenshot of the prompt:

Console logging “#” depends on the input that you provide. The examples from the screen shot above do a great job at showing what the input and output values should be for this problem. If our input is 4 then this is what the output should be:

'#   ''##  ' '### ' '####'

In this case, we can look at the output as some form of table with rows and columns. If we look at the example inputs, Notice that there are empty spaces inside the string until the string is full of #.

This time, I’ll be using recursion to solve this problem. In simpler terms, a recursive function can call on itself until it can’t anymore. One example of recursion is the Fibonacci sequence (0,1,1,2,3,5,8,...). For more info on recursions, and the Fibonacci sequence please check out the resource section.

Instead of creating for loops we’re just going to create a few conditionals and at one point call the function (in this case steps()). Here’s a screenshot of my pseudo code:

Here’s a screenshot of my solution:

Here are the results from the example on line 74:

For more info on recursions check the resource section below!