I've encountered printing geometric figures (it's a basic kind of problem) using asterisks. These are not homeworks. I'm fascinated with patterns but don't know how to think about these problems in an analytical way. Please help if you can.
One is a diamond. Originally, I did't get how they established the constants (i.e. 5), the iteration numbers (0-2*N), or the testing values (especially 3*N-i). These numbers all seemed arbitrary. Someone pointed out that 5 is like the radius of the diamond. So I assume that means the 2*N gives the diameter and is needed in order to draw the top and bottom halves.
Something that confuses me is why are there 11 lines instead of 10 if the radius is 5?
Does the term 3*N-i just come from observation or is there a way to derive it mathematically?
The other figure is a triangle. I don't understand what about the problem tells us that we're supposed to notice that the bitwise inversion of the outer loop counter bitwise anded with the inner loop counter will give us a nice triangle pattern.
How do you know to invert the row counter and AND it against the column counter?