Horner's rule for polynomial evaluation: Difference between revisions
Content added Content deleted
(add RPL) |
m (→{{header|Sidef}}: update) |
||
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.last(-1), x)) |
|||
: 0 |
|||
} |
} |
||
say horner([-19, 7, -4, 6], 3) |
say horner([-19, 7, -4, 6], 3) # => 128</syntaxhighlight> |
||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |