After doing some intense Googling for a Diamond Problem solver in java, all I could find was the OOP diamond problem. That’s not what I’m after. What I’m looking for is a simple function in java to find the solution to a diamond problem.
A diamond problem can be expressed like this:
A = C * D,
B = C + D
So, if:
A = 10, B = 7
C = 5, D = 2
What I’m attempting to do is solve a diamond problem in java quickly and effectively. I’ve tried nested for loops, but they’re extremely inefficient due to the nature of the program.
If anyone has any ideas, I would love to hear them.
Thanks!
If we observe the following algebra:
B^2 - 4A = (C^2 + 2CD + C^2) - 4CD = (C^2 - 2CD + D^2) = (C-D)^2Then we can quickly and easily make this function:
By the way, this will generate problems if
4Ais bigger thanB^2… in that case the answers are imaginary anyway.