多项式长除法

10

（12x ^ 3-5x ^ 2 + 3x-1）/（x ^ 2-5）= 12x-5 R 63x-26

3

J，94

``````f=:>@(0&{)
d=:0{[%~0{[:f]
D=:4 :'x((1}.([:f])-((#@]{.[)f)*d);([:>1{]),d)^:(>:((#f y)-(#x)))y'
``````

``````(1 0 _5) D (12 _5 3 _1;'')
63 _26 | 12  _5
``````

``````#a
4
``````

``````(#a) {. b
1 0 -5 0
``````

``````(0{a) % (0{b)
12
``````

``````a - 12*b
12 0 _60
``````

``````a f^:n b
``````

JB

@JB：1）不，实际上，“通常”订单的时间可能更短；这就是我开始考虑的方式。2）它是数组的一部分，所以我它应该是输入的一部分。
Eelvex

JB

3

Python 2中，260个258 257 255字节

``````exec'''def d(p,q):
R=range;D=len(p);F=len(q)-1;d=q[0];q=[q[i]/-d@R(1,F+1)];r=[0@R(D)];a=[[0@R(F)]@R(D)]
@R(D):
p[i]/=d;r[i]=sum(a[i])+p[i]
for j in R(F):
if i<D-F:a[i+j+1][F-j-1]=r[i]*q[j]
return r[:D-F],[d*i@r[D-F:]]'''.replace('@',' for i in ')``````

``````def d(p,q):
R=range;D=len(p);F=len(q)-1;d=q[0];q=[q[i]/-d for i in R(1,F+1)];r=[0 for i in R(D)];a=[[0 for i in R(F)] for i in R(D)]
for i in R(D):
p[i]/=d;r[i]=sum(a[i])+p[i]
for j in R(F):
if i<D-F:a[i+j+1][F-j-1]=r[i]*q[j]
return r[:D-F],[d*i for i in r[D-F:]]``````

``````>>>d([12., -5., 3., -1.],[1.,0.,-5.])
([12.0, -5.0], [63.0, -26.0])``````

1

xnor 2014年

@xnor我已经做了另一遍，但是不止一次替换。

2

哈斯克尔（126）

``````l s _ 0=s
l(x:s)(y:t)n=x/y:l(zipWith(-)s\$map(*(x/y))t++repeat 0)(y:t)(n-1)
d s t=splitAt n\$l s t n where n=length s-length t+1
``````

``````*Main> d [12, -5, 3, -1] [1, 0, -5]
([12.0,-5.0],[63.0,-26.0])
``````

1

带lambdas的JavaScript，108

``````f=(a,b)=>{for(n=b.length;a.length>=n;a.shift())for(b.push(k=a[q=0]/b[0]);q<n;++q)a[q]-=k*b[q];b.splice(0,n)}
``````

``````f(x=[12,-5,3,-1], y=[1,0,-5]), console.log(x, y)
// Array [ 63, -26 ] Array [ 12, -5 ]
``````

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.