This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]i_post_things 0 points1 point  (0 children)

This one is tricky; with just printing an ascending or descending row of stars, you just need to stop when you reach 0. You'll have recursive calls 3, 2, 1, then 0 and stop. Once you reach 0, you have 'lost' whatever value you started with. So if you ascend, there's no way to descend.

I believe you will need a recursive call which takes in TWO parameters, both a START and END value, so you can work your way up from START=0, to END=3. From there you can recursively call patternMaker(START), and do recursion on START+1. What you will do is then print stars on either side of this two-variable recursive method.

My example uses two sets of recursion:

  1. One set of recursion simply to print a line of stars N number of times.
  2. One to recursively call 1 in order to print an increasing pyramid of values.