Ad
Code
Diff
  • from math import prod
    
    • from functools import reduce
    • from operator import __mul__
    • def prod(numbers):
    • return reduce(__mul__, numbers) if numbers else 0
    • from math import prod
Code
Diff
  • from functools import reduce
    from operator import __mul__
    def prod(numbers):
        return reduce(__mul__, numbers) if numbers else 0
    • from functools import reduce
    • from operator import __mul__
    • def prod(numbers):
    • if numbers == []: return 0
    • product = 1
    • for number in numbers:
    • product *= number
    • return product
    • return reduce(__mul__, numbers) if numbers else 0

A polynomial can be written in the form ax^n + bx^n-1 +.. z
Degree will be <=8.

Return an array of the unique real roots.

e.g. a=1, b=3, c=2, d=0 --> [0, -1, -2]

import numpy
import re
def real_solutions(a='x',b='x',c='x',d='x',e='x',f='x',g='x',h='x'):
    arr = [x for x in [a,b,c,d,e,f,g,h] if isinstance(x,int)]
    b = numpy.roots(arr).tolist()
    return list(dict.fromkeys([round(x.real,5) for x in b if abs(x.imag)<1e-5]))