There is just one pair of numbers (x,y) where when you add them together, multiply them together or divide x by y, the answers are all equal. What are those numbers?
If you'd like to have a go at finding the answer, please do, and I'd love to hear how you did it.
Below are my thoughts, experiments and answer.
I should have found the answer sooner than I did. First of all I used BASIC, set up a couple of loops for x and y and tested for meeting the conditions. That didn't produce an answer and so I did try smaller steps and included negative numbers. I now know that I should have found the answer then but for some reason my program didn't produce the result.
Wanting to at least find the ballpark , I thought about ways to plot these three conditions on a graph. A 2d graph wouldn't really do it because we want to test all values of x and y. I tried using some 3d graphing systems to plot z=x+y, z=x*y and z=x/y, to see where they all intersected. But it was way too difficult to see what was going on.
I devised a way to get a 'Z' value which will be zero when the answers to all three tests are zero. I was hoping to at least be able to see roughly where the answer lies and you can see that there's clearly one point where this graph comes close to z=0.
My solution on paper with algebra!:
ReplyDeletex+y = xy = x/y start
xy+y^2 = xy^2 = x mul by y
y+y^2/x = y^2 = 1 div by x
y^2 = 1 *hence y = ±1*
±1 + 1/x = 1 substitute y = ±1 in
±x + 1 = x mul by x
x + 1 = x does not work since then 1 = 0
hence 1 - x = x
1 = 2x
x = 0.5
if y is positive 1 the values dont work (1.5 = 0.5 = 0.5)
if y is negative 1 the values do work (-0.5 = -0.5 = -0.5)
hence y = -1 and x = 0.5
Thank you so much for this. I didn't think this question could be solved this way.
ReplyDeleteyep! and for completeness, my python solution to bruteforce it:
Delete# python range() is only for ints
def fltrange(start, end, step):
res = []
i = start
while i < end:
res.append(i)
i += step
return res
sampmin = -5
sampmax = 5
precision = .005
bestmatch = [] # the match x, y
matchthres = 99999 # how accurate it was
# sample a load of points and find the best match
for x in fltrange(sampmin, sampmax, precision):
for y in fltrange(sampmin, sampmax, precision):
diff1 = (x+y) - (x*y)
diff2 = (x+y) - (x/y)
diff3 = (x*y) - (x/y)
meanDiff = (abs(diff1) + abs(diff2) + abs(diff3)) / 3
if meanDiff < matchthres:
matchthres = meanDiff
bestmatch = [x, y]
# its not perfect, but it gets almost there
# bestmatch.Select(n => round(n)).ToArray()
# this rounds to 10 decimal places and hits the exact result
list(map(lambda n: round(n, 10), bestmatch))