| Bytes | Lang | Time | Link |
|---|---|---|---|
| 264 | Haskell | 140608T051447Z | MtnViewM |
| 645 | Python | 130611T200004Z | jadkik94 |
Haskell - 264 bytes
p(a:b:s)=(a,b):p s
p[a]=[(a,0)]
p[]=[]
s((a:w),m@(b:v))=a:s(m,m%zipWith(\c d->(b*c-a*d)/b)w v)
s((a:_),_)=[a]
m%(0:v)|all(==0)v=fst$foldr(\b(d,p)->(b*p:d,2+p))([],0)m
m%v=v
q(a:s)|all((>0).(a*))s="1\n"
q _="0\n"
main=interact$(>>=q.s.unzip.p.map read.words).lines
Running the sample inputs:
& runhaskell 11847-Stability.hs
1 12 6 10 10 6 14
1 1 -2
1 2 1 2
1 3 1 3 16
1 2 3 6 2 1
1 2 14 88 200 800
1 2 3 6 2 1
1 3 6 12 8
1 4 5 2 4 16 20 8
0
0
1
0
0
0
0
1
0
(The output is interleaved with the input if you type it one line at a time, as per spec. If you bulk paste, you see all the output after the input.)
Python (645 bytes)
That's what I managed to do (and golf):
from decimal import*
R=xrange
def s(p):
d=len(p)
if 0 in p:return 0
elif sum(1 for c in p if c>0) not in (0,d):return 0
p=p+[0] if d%2 else p[:]
r=[[0 for j in R(len(p)//2)] for i in R(d)]
r[:2]=[[v for v in p[i::2]] for i in (0,1)]
for i in R(2,len(r)):
a,h,b = 1,0,0
for k in R(len(r[i])-1):
v=(r[i-1][0]*r[i-2][k+1]-r[i-2][0]*r[i-1][k+1])/r[i-1][0]
r[i][k],a,h,b=v,a and v==0,h or v==0,b or (h and v!=0)
if a:r[i]=[v*max(0,d-i-2*k) for k,v in enumerate(r[i-1])]
elif b:return False
return sum(1 for v in r if v[0]>0) in (0,d)
while 1:
r=raw_input()
if not r:break
print 1 if s([Decimal(x) for x in r.split()]) else 0
It takes as input the coefficients of the polynomials in decreasing order (highest power of s to lowest 0).