## Nova polynomial add

This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8807940ff3001140 ) [#4](http://www.codewars.com/kata/571a2e2df24bdfd4e20001f5) )

Consider a polynomial in a list where each element in the list element corresponds to a factor. The factor order is the position in the list. The first element is the zero order factor (the constant).

`p = [a0, a1, a2, a3]` signifies the polynomial `a0 + a1x + a2x^2 + a3*x^3`

In this kata add two polynomials:

```python
poly_add ( [1, 2], [1] ) = [2, 2]
```

Difficulty: introductory

Starter code:

def poly_add(p1, p2):
	

Solutions:
# return the sum of the two polynomials p1 and p2.  
def poly_add(p1,p2):
    if p1 == []:
        return p2
    if p2 == []:
        return p1
    return [p1[0] + p2[0]] + poly_add(p1[1:], p2[1:])


from itertools import zip_longest
def poly_add(p1, p2):
    return [x+y for x, y in zip_longest(p1, p2, fillvalue=0)]

# return the sum of the two polynomials p1 and p2.  
def poly_add(p1, p2):
    # store the result here
    res = []
    longest_p = max(len(p1), len(p2))
    for i in range(longest_p):
        # add the two numbers together unless there is no number there, then just add 0 (don't change)
        res.append((p1[i] if i < len(p1) else 0) + (p2[i] if i < len(p2) else 0))
    return res

from itertools import zip_longest

def poly_add(*polys):
    return [sum(coeffs) for coeffs in zip_longest(*polys, fillvalue=0)]


def poly_add(p1, p2):
    p = p1[len(p2):] if len(p1)>len(p2) else p2[len(p1):]
    return [i+j for i,j in zip(p1,p2)]+p


from itertools import zip_longest

def poly_add(p1, p2):
    return list(map(sum, zip_longest(p1, p2, fillvalue=0)))

def poly_add(p1, p2):
  s, l = sorted([p1, p2], key=lambda p: len(p))
  x = [sum(f) for f in zip(s, l)]
  x.extend(l[len(s):])
  return x

def poly_add(a, b):
    lmax = max(len(a), len(b))
    a += [0]*(lmax - len(a))
    b += [0]*(lmax - len(b))    
    return list(map(sum, zip(a,b)))

def poly_add(a, b):
    res = []
    if len(b)>len(a):
        a, b = b, a

    for i,n in enumerate(a):
        try:
            res.append(n+b[i])
        except:
            res.append(n)
        
    return res