bperlman·4 năm trước·discussI'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 = sx * y = px = s - yx = p/ysubstitute for xp/y = s - yp = sy - y*2y*2 - sy + p = 0# use the quadratic formula to solve for yy = (-b ± √(b²-4ac)) / (2a)In python:import numpy as npx = np.random.randint(1,100)y = np.random.randint(1,100)s = x+yp = xya = 1b = -1sc = py_solved = (-1b + (b*2 - 4ac)*.5)/(2a),(-1b - (b*2 - 4ac)*.5)/(2a)print(x,y,y_solved)
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)