Horner's rule for polynomial evaluation: Difference between revisions

Content added Content deleted
(add scala example)
Line 478: Line 478:
p horner([-19, 7, -4, 6], 3) # ==> 128</lang>
p horner([-19, 7, -4, 6], 3) # ==> 128</lang>


=={{header|Scala}}==
<lang scala>def horner(coeffs:List[Double], x:Double)=
coeffs.reverse.foldLeft(0.0){(a,c)=> a*x+c}
</lang>
<lang scala>val coeffs=List(-19.0, 7.0, -4.0, 6.0)
println(horner(coeffs, 3))
-> 128.0
</lang>
=={{header|Sather}}==
=={{header|Sather}}==
<lang sather>class MAIN is
<lang sather>class MAIN is