Marcos Pires
New member
- Joined
- Oct 11, 2016
- Messages
- 5
Hello,
I have a programming problem and although it is a simple one I'm trying to solve it with math, taking a more painful approach. I want to have an equation because the value for X and Y can vary.
The problem: Given an odd number, draw a diamond. Ex. 7
*
***
*****
*******
*****
***
*
You can note that the amount of * increase then decrease which lead me to think about quadratic equations. On this example we can think as each line as X and the amount of * as Y. Note that the last line is 7 and the line with most stars has 7 stars, meaning that these values are connected with the given number, 7.
so we have X from 1 to 7 and Y as 1,3,5,7,5,3,1
Y = 1 X = 1
Y = 3 X = 2
Y = 5 X = 3
Y = 7 X = 4
Y = 5 X = 5
Y = 3 X = 6
Y = 1 X = 7
OR
Y = 1, X = 1 or X = 7
Y = 3, X = 2 or X = 6
Y = 5, X = 3 or X = 5
Y = 7, X = 4 or X = 4
I`ve tried and tried, but I can't come up with a quadratic function that express this relation. I've tried combining all the formulas for either solve a quadratic or find the vertix (which is know since I would have X and Y at all times) but I can't come up with a, b or c. Also, I believe that 'a' will always be negative.
please help?
I have a programming problem and although it is a simple one I'm trying to solve it with math, taking a more painful approach. I want to have an equation because the value for X and Y can vary.
The problem: Given an odd number, draw a diamond. Ex. 7
*
***
*****
*******
*****
***
*
You can note that the amount of * increase then decrease which lead me to think about quadratic equations. On this example we can think as each line as X and the amount of * as Y. Note that the last line is 7 and the line with most stars has 7 stars, meaning that these values are connected with the given number, 7.
so we have X from 1 to 7 and Y as 1,3,5,7,5,3,1
Y = 1 X = 1
Y = 3 X = 2
Y = 5 X = 3
Y = 7 X = 4
Y = 5 X = 5
Y = 3 X = 6
Y = 1 X = 7
OR
Y = 1, X = 1 or X = 7
Y = 3, X = 2 or X = 6
Y = 5, X = 3 or X = 5
Y = 7, X = 4 or X = 4
I`ve tried and tried, but I can't come up with a quadratic function that express this relation. I've tried combining all the formulas for either solve a quadratic or find the vertix (which is know since I would have X and Y at all times) but I can't come up with a, b or c. Also, I believe that 'a' will always be negative.
please help?