Polynomial Sequences part 2 by yowa

#!ruby -na
a=$F.map(&:to_i)
puts ((1..n=a.size).map{n-=f=1
b=a
n.downto(1){|i|f*=i
b=(1..i).map{|j|b[j]-b[j-1]}}
k=b[0]/f
a=(1..n).map{|x|a[x-1]-k*x**n}
k==0?'':" %+dx^%d"%[k,n]}*'').gsub(/\A \+?|\^1|x\^0/,'').gsub(/1x/,'x')

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return top