# Thread: Need help developing analytical skills

1. ## Need help developing analytical skills

Hi,

Please help me develop some reasoning skills for these two small programs.

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;
}
}```

2. 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).

3. ## 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.

Thank you for replying,
Frank

4. 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.

5. ## 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.

Thank you for replying,
Frank

6. 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.

Thank you for replying,
Frank
My point was that the radius cannot be derived from anything. It is what it is, and must be given. The others will derive from it. You will derive the other numbers by counting. Specifically, for each line you must count the positions where the spaces on the right start and the spaces on the left end. Once you have counted each row, then the derivation kicks in: you need to write down an equation that gives you the numbers you have counted.

You can't derive anything for the bottom figure, because there's nothing there that was derived. That's just the pattern of how "and" works. If you know how "and" and "not" work, then you know what that pattern is. If you don't know how "and" and "not" work, then you need to learn how "and" and "not" work, and then you will know the pattern. It's essentially a truth table printed with '*' and ' ' instead of 'T' and 'F'.

Popular pages Recent additions