# Need help developing analytical skills

• 10-01-2009
lanef
Need help developing analytical skills
Hi,

They draw geometric figures and I've never been exposed to their likes before.

One is a diamond and what I don't get are how they establish the constants (i.e. 5), the iteration numbers (0-2*N),

or the testing values (especially 3*N-i). These numbers all seem arbitrary but I'd like to understand how they

arrived at the numbers analytically.

The other 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. Any help will be greatly appreciated.

Thanks,
lanef

Diamond

PHP Code:

```      *     ***    *****   *******  ********* ***********  *********   *******    *****     ***      *  ```
Diamond Code
Code:

```#include <iostream> void main() {   const int N=5;   for (int i = 0; i <= 2 * N; i++) {       for (int j = 0; j <= 2 * N; j++) {         if (i <= N) {             if (j < N - i || j > N + i) {               std::cout << ' ';             }             else {               std::cout << '*';             }         }         else {             if (j < i - N || j > 3 * N - i) {               std::cout << ' ';             }             else {               std::cout << '*';             }         }       }       std::cout << std::endl;   } }```
Triangle

PHP Code:

``` * ** * * **** *   * **  ** * * * * ******** *       * **      ** * *     * * ****    **** *   *   *   * **  **  **  ** * * * * * * * * ****************  ```
Triangle Code
Code:

```#include <iostream> void main() {   const int N = 16;   for (int n = 0; n < N; n++) {       for (int k = 0; k <= n; k++) {         std::cout << ((~n & k) != 0 ? ' ' : '*');       }       std::cout << std::endl;   } }```
• 10-01-2009
tabstop
5 is the size of the diamond (radius if you will -- the number of rows in the top half). To figure out where the numbers come from, you should draw the figure (which you appear to have done) and then count (which you appear to have not done).
• 10-02-2009
lanef
Need help developing analytical skills
Hi,

I guess I didn't make myself clear? You seem to understand these problems. I don't. Saying that the radius of the diamond is 5 doesn't help alot.

Please criticize this statement if it's not what you were hinting at. "Knowing the radius is 5 does help me to see that the diameter then drives the iteration limits, and that you have to go up to the diameter and then include it because there are really eleven rows and columns, not ten."

I still don't understand how to arrive at the 3*N-i term analytically. I can kinda see it as a trial and error thing but would like to understand it along the lines of "Okay, the radius of the diamond is 5 therefore you have to discriminate the lower right area by 5.mathoperation(radius) = 3".

And counting and drawing don't help me understand the triangle problem at all.

Frank
• 10-02-2009
stevesmithx
I guess you didn't write the program. Someone did and you are trying to understand the code. Am I right?. If that is the case i suggest using a debugger and trace and watch the counter variables of the loop. It would certainly help you a lot. Also main should return int not void.
• 10-02-2009
lanef
Need help developing analytical skills
Hi Steve,

Yup, you're right. It's not that simple to me to understand it either. I've gotta figure out how to run my command line debugger but that's a great idea I didn't think of.

Frank
• 10-02-2009
tabstop
Quote:

Originally Posted by lanef
Hi,

I guess I didn't make myself clear? You seem to understand these problems. I don't. Saying that the radius of the diamond is 5 doesn't help alot.

Please criticize this statement if it's not what you were hinting at. "Knowing the radius is 5 does help me to see that the diameter then drives the iteration limits, and that you have to go up to the diameter and then include it because there are really eleven rows and columns, not ten."

I still don't understand how to arrive at the 3*N-i term analytically. I can kinda see it as a trial and error thing but would like to understand it along the lines of "Okay, the radius of the diamond is 5 therefore you have to discriminate the lower right area by 5.mathoperation(radius) = 3".

And counting and drawing don't help me understand the triangle problem at all.