Horner's rule for polynomial evaluation: Difference between revisions

Content added Content deleted
(add RPL)
Line 2,464: Line 2,464:
Recursive:
Recursive:
<syntaxhighlight lang="ruby">func horner(coeff, x) {
<syntaxhighlight lang="ruby">func horner(coeff, x) {
coeff.len > 0
(coeff.len > 0) \
&& (coeff[0] + x*horner(coeff.ft(1), x));
? (coeff[0] + x*horner(coeff.last(-1), x))
: 0
}
}


say horner([-19, 7, -4, 6], 3); # => 128</syntaxhighlight>
say horner([-19, 7, -4, 6], 3) # => 128</syntaxhighlight>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==