Scheme
I want to define a function which returns the roots of the quadratic formula, given ax^2+bx+c=0. Return only real roots. The list will have 0, 1, or two unique roots.
(define (quadratic a b c)
(cond
((> (- (* b b) (* 4 (* a c ) ) ) 0 ) (list ( / ( - (sqrt ( - (* b b) (* (* 4 a) c))) b ) ( * 2 a) )
( / ( - ( - (sqrt ( - (* b b) (* (* 4 a) c)))) b ) ( * 2 a) ) ) )
((= (- (* b b) (* 4 (* a c ) ) ) 0 ) list( / ( - (sqrt ( - (* b b) (* (* 4 a) c))) b ) ( * 2 a) ))
(else ('( )'))
)
)
I got
error: unexpected right parenthesis [read]
#{&read-error}
#{&i/o-port-error #{input-port #{input-channel "standard input" 0}}}
Is there any better way to solve that?
listis not random, OP is using it to return a list with the answers. - Óscar López