Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

77%
+5 −0
Challenges Evaluate a single variable polynomial equation

Ruby, 50 bytes def f(k,x)k.length>1?k[0]+f(k[1..-1],x)*x:k[-1]end Try it online! This uses the Horner's method recursively, because I think it'll be slightly shorter than using a loop or bu...

posted 4y ago by luap42‭

Answer
#1: Initial revision by user avatar luap42‭ · 2020-11-13T23:29:10Z (about 4 years ago)
# Ruby, 50 bytes

```ruby
def f(k,x)k.length>1?k[0]+f(k[1..-1],x)*x:k[-1]end
```

[Try it online!](https://tio.run/##KypNqvz/PyU1TSFNI1unQjNbLyc1L70kw87QPjvaIFYbKBptqKenaxgLlNSqsMqOBjJT81L@F5SWFAP1ACUNYnUUDC2MNLmQhHQUjMDiJghRIz1TmKiBnimmah0FYxBhAjEPqOI/AA "Ruby – Try It Online")

This uses the [Horner's method](https://en.wikipedia.org/wiki/Horner%27s_method) recursively, because I think it'll be slightly shorter than using a loop or builtin array functions.

Also, this is my first post on this website ... er my first real attempt at golfing something in Ruby, so please feel free to suggest ways to shorten my solution.