You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
Given integer coefficients a b c
of a quadratic equation ax^2 + bx + c = 0
Output the corresponding root(s) in exact simplified form [n1[/d1]] [±] [[i][√]n2[/d2]]
where each bracketed element must be omitted if possible
Possibilities/Concerns
should there be parens √(n2)? should d2 be included in the sqrt or outside? Might be more aesthetically pleasing as [[√(]n2[/d2][)][i]]
could also print solutions comma separated, which cleans up some outputs but makes others worse, could specify cases to use and cases not to?
should 0 0 0 => indeterminate and 0 0 x => undefined be cases to consider or left out?
could also use input strings of the form ax^2 + bx + c or ax^2 + bx + c = 0 or ax^2 + bx + c = d which would look nice but likely would be unnecessary overhead and more trouble than its worth
Example input
These were all done by hand, let me know if you spot mistakes, i'll start working on a program to automatically generate solutions
0
5
-4/3
-1, 1 | ±1
-i, i | ±i
-√5, √5 | ±√5
-7/11, 1/2 | -3/44 ± 25/44 this one is an outlier but does come out uglier with the ±
1/4 - √17/4, 1/4 + √17/4 | 1/4 ± √17/4
-1/2 - i√39/6, -1/2 + i√39/6 | -1/2 ± i√39/6 (-1/2 ± √(13/12)i)? ((-1 ± √(13/3)i)/2)?
indeterminate
undefined
EDIT: idrk what i'm doing i've never coded in go before but i think i should have a valid experimental hole implementation. #940.
I think I could be more clever about generating test cases, right now i'm just generating 200 sets of random coefficients, but it would be good to guarantee every possible case is represented
The text was updated successfully, but these errors were encountered:
For many languages, a lot of work will be done reducing fractions. Here's another idea: Guarantee that the equations have one or two real solutions. The results should be printed in decimal format with a fractional part of a few fixed digits, maybe as little as two. So the output would be something like:
1.23 -4.56
-0.01 -0.01
3.00
0.00
If there's an exact solution with that many digits, it must be printed. Rounding issues could be handled:
Require round toward zero (cut off the decimal expansion).
You're allowed to round up or down. This obviously requires a bit of extra work when verifying solutions.
Description
Given integer coefficients
a b c
of a quadratic equation
ax^2 + bx + c = 0
Output the corresponding root(s) in exact simplified form
[n1[/d1]] [±] [[i][√]n2[/d2]]
where each bracketed element must be omitted if possible
Possibilities/Concerns
√(n2)
? shouldd2
be included in the sqrt or outside? Might be more aesthetically pleasing as[[√(]n2[/d2][)][i]]
0 0 0 => indeterminate
and0 0 x => undefined
be cases to consider or left out?ax^2 + bx + c
orax^2 + bx + c = 0
orax^2 + bx + c = d
which would look nice but likely would be unnecessary overhead and more trouble than its worthExample input
These were all done by hand, let me know if you spot mistakes, i'll start working on a program to automatically generate solutions
Example output
EDIT: idrk what i'm doing i've never coded in go before but i think i should have a valid experimental hole implementation. #940.
I think I could be more clever about generating test cases, right now i'm just generating 200 sets of random coefficients, but it would be good to guarantee every possible case is represented
The text was updated successfully, but these errors were encountered: