1. Member
Join Date
Sep 2010
Posts
62
Rep Power
0
Originally Posted by Fubarable
It's all about generating equations from patterns. If we linearize the data by making it a straight line without a "reflection" like so:

Java Code:
```x		y
===================
0		4
1		3
2		2
3		1
4		0
5		-1
6		-2
7		-3
8		-4```
We see that this is the plot of a line with slope -1 that intersects the y axis at 4 which mathematically means:

y = -x + 4

To make all negatives positive, I must take the absolute value of the right side:

y = |4 - x|

Substituting i for x and spaceMax for y and using the Java Math method for obtaining absolute value gives:

Java Code:
`spaceMax = Math.abs(C - i);`
Where C is a constant that here = 4.

Now when we play around with different values of MAX and check to see how this affects C we get:
Java Code:
```MAX		C
===================
3		1
5		2
7		3
9		4
11		5
13		6```
we see that C = ((MAX - 1) / 2.0)
but since int division tosses out any remainder, in Java, C is nothing more than MAX / 2

Thanks for the great explanation, Fubarable.

Why have you decided to substitute y with spaceMax (not with starMax):
Java Code:
`spaceMax = Math.abs(C - i);`

I am not sure I understand the last section:
Now when we play around with different values of MAX and check to see how this affects C we get:
Java Code:
```MAX        C
===================
3        1
5        2
7        3
9        4
11      5
13      6```
we see that C = ((MAX - 1) / 2.0)
but since int division tosses out any remainder, in Java, C is nothing more than MAX / 2
You are playing with different values of spaceMax?
Last edited by luke; 10-18-2010 at 07:04 PM.

2. Member
Join Date
Sep 2010
Posts
62
Rep Power
0
Just lifting up my post. I hope you would have a couple of minutes for my questions.

3. Originally Posted by luke
Thanks for the great explanation, Fubarable.

Why have you decided to substitute y with spaceMax (not with starMax):
Java Code:
`spaceMax = Math.abs(C - i);`
Because the data points most closely resembled the spaces data in a post earlier in this thread but without the "reflection" at the origin.

I am not sure I understand the last section:

You are playing with different values of spaceMax?
I was playing with different values for all variables, and especially for MAX.

4. Member
Join Date
Sep 2010
Posts
62
Rep Power
0
Following all your advice I tried to display a triangle this time. After spending some hours trying to figure out which of my formulas to use and for what I eventually made it.

Java Code:
```static void printTriangle() {

final int MAX = 7;

for(int i = 0; i <= (MAX - 1) / 2; i++) {

int space = MAX / 2 - i;
for( int j = 0; j < spaces; j++)
System.out.print(' ');

for ( int k = 0; k < MAX - 2 * spaces ; k++)
System.out.print('*');

System.out.println();

}```

If you look into my code to see how I solved this problem do you think I've understood what you've explained to me or it could have been done in a better (more flexible) way?

Page 2 of 2 First 12

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•