Skip to main content
1 of 6
kzidane
  • 17.7k
  • 3
  • 28
  • 100

Five months is too long for a problem like mario or pretty much any other problem in the course.

You could try solving it manually with low-tech tools (e.g., a pencil and a paper) trying to draw half a pyramid row-by-row from top to bottom.

Suppose the input is 5, we should get the following output:

    ##
   ###
  ####
 #####
######

By analyzing the problem, we can get a lot of info such as:

  1. the initial number of spaces to be printed out in terms of the height (i.e., 5) is height - the initial number of hashes.
  2. the initial number of hashes is 2.
  3. the number of spaces decreases each row until it becomes 0 in the last row.
  4. the number of hashes increases by 1 until it becomes height + 1 in the last row.

Using these information and a little more, I could write the following pseudocode (assuming height is a valid integer inputted by the user):

calculate the initial number of spaces in terms of height
calculate the initial number of hashes in terms of height

// draw the rows
for (int i = 0; i < height; i++)
{
    // draw spaces
    for (int j = 0; j < spaces; j++)
        print a space

    // draw hashes
    for (int j = 0; j < hashes; j++)
        print a hash
    
    move to the next row
    decrement the number of spaces
    increment the number of hashes
}
kzidane
  • 17.7k
  • 3
  • 28
  • 100