-
Notifications
You must be signed in to change notification settings - Fork 1
/
Polynomial.py
38 lines (28 loc) · 868 Bytes
/
Polynomial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import random
class Polynomial:
st = range(0, 149)
def __init__(self):
self.degree = 0
self.generate()
def generate(self):
self.degree = random.choice(Polynomial.st)
Polynomial.st.pop()
def __str__(self):
return "x^" + str(self.degree)
def get_degree(self):
return self.degree
def poly_random(values):
polynomials = []
for i in range(0, values['count']):
poly1 = Polynomial()
poly2 = Polynomial()
poly3 = Polynomial()
polynomial = str(poly1) + " + " + str(poly2) + " + " + str(poly3)
polynomials.append(polynomial)
return polynomials
def highest_degree(polynomial):
poly = polynomial['polynomial']
polys = poly.split("+")
polys = map(lambda x: x.replace("x^", ""), polys)
degrees = map(int, polys)
return max(degrees)