Skip to content

Instantly share code, notes, and snippets.

@akiray03
Last active January 13, 2016 04:20
Show Gist options
  • Select an option

  • Save akiray03/c7412978bcbedb24f07f to your computer and use it in GitHub Desktop.

Select an option

Save akiray03/c7412978bcbedb24f07f to your computer and use it in GitHub Desktop.
def polynomial(numbers, x)
r = 0
numbers.each_with_index do |n, i|
r += n * x**i
end
r
end
def polynomial2(numbers, x)
ary = [1, x]
(numbers.size - 2).times do |i|
ary << ary[-1] * x
end
r = 0
numbers.each_with_index do |n, i|
r += n * ary[i]
end
r
end
# a0 + a1*x + a2*x**2 + a3*x**3 + a4*x**4 ...
# = a0 + x * (a1 + a2*x + a3*x**2 + a4*x**3 ... )
# = a0 + x * (a1 + x * (a2 + a3*x + a4*x**2 ... ) )
def polynomial3(numbers, x)
# 力尽きた
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment