3
0
Challenge:
Write the smallest program (in characters) that resolves quadratic equations
i.e. ax² + bx + c = 0
Rules:
Given 3 numbers in R comma-delimited on STDIN: a,b,c (a != 0), print on STDOUT the 2 roots in C, one per line.
R stands for real numbers, C for complex numbers.
Examples:
Input Output
1,0,0 r1=0 also accepted: r1=(-0-sqrt(0))/2
r2=0
1,2,1 r1=-1 also accepted: r1=(-2-sqrt(0))/2
r2=-1
1,1,1 r1=(-1-isqrt(3))/2 also accepted: r1=(-1-sqrt(-3))/2 or r1=-0.5-0.866i
r2=(-1+isqrt(3))/2
What does
isqrt
mean? Are there any constraints on the output format (e.g. canonical forms) or is any expression which resolves to the roots valid? – Peter Taylor – 2011-11-28T16:01:39.887@Peter Taylor: isqrt stands for i * squareRoot(3). The output have to be on 2 lines as shown in the output column of examples. – Toto – 2011-11-28T16:06:25.837
But would
r1=(-2-sqrt(0))/2
be an acceptable output line? How aboutr1=(-1-sqrt(-3))/2
? – Peter Taylor – 2011-11-28T17:27:48.077@Peter Taylor: I see what you mean, yes both output are acceptable. – Toto – 2011-11-28T18:35:39.847
I implemented this using a Casio fx-7000G - http://www.rskey.org/detail.asp?manufacturer=Casio&model=fx-7000G - (not sure the extact model). I remember there being only 32 steps for a program and the version I came up with was 31 (including the data entry).
– Skizz – 2011-11-29T13:47:57.380