HackerTrans
TopNewTrendsCommentsPastAskShowJobs

bperlman

no profile record

comments

bperlman
·4 tahun yang lalu·discuss
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 = -1
s

c = p

y_solved = (-1b + (b*2 - 4ac)*.5)/(2a),(-1b - (b*2 - 4ac)*.5)/(2a)

print(x,y,y_solved)