|
|
|
|
|
by bperlman
1497 days ago
|
|
I'm confused: If Sandy tells Peter her sum, why doesn't Peter use the quadratic formula to solve for the x,y pair algebraically? x + y = s x * y = p x = s - y x = p/y substitute for x p/y = s - y p = sy - y*2 y*2 - sy + p = 0 # use the quadratic formula to solve for y y = (-b ± √(b²-4ac)) / (2a) In python: import numpy as np x = np.random.randint(1,100) y = np.random.randint(1,100) s = x+y p = xy a = 1 b = -1s c = p y_solved = (-1b + (b*2 - 4ac)*.5)/(2a),(-1b - (b*2 - 4ac)*.5)/(2a) print(x,y,y_solved) |
|