OJ's rants

It's not about you, it's about the software

Challenge #2 - the Recursive Ruler

| Comments

I posted this problem a little while ago on the site I used to run, and it proved to be an interesting one that resulted in quite a large collection of solutions from the posters. So here it is again.

Your job is to write a program that generates a text-based ruler. For a clearer definition of what I mean, see the little text pic below:

|                               |                               |
|               |               |               |               |
|       |       |       |       |       |       |       |       |
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

The user of the program must be able to specify a couple of parameters: those being the height of the ruler and the number of sections in the ruler (at the top level). In the above example, the values would be 6 and 2 respectively. Another example, using the values 3 and 3 would result in:

|   |   |   |
| | | | | | |
|||||||||||||

The only other thing that you have to do is make sure that your solution uses recursion instead of iteration. Feel free to use any language you want, you can write to screen or to file, it’s your call. But you must use recursion.

I look forward to seeing your responses. :) Happy coding!

Comments