Skip to main content

Friday Quiz maths question, 24 Jun 2022, a day late.

 

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.


Using this graph and twirling it around a lot, you can just about tell that the answer is somewhere around y = -1 and x = 0.5.  And these numbers do fit the question.


I then went back to BASIC and used this program to produce the answer.

There's a pitfall when using floats (which we need to do here). You can't reliably test for equality or equality with zero. However, after experimenting with this, it does seem that the "if a=b and b=c" does work here in commodore basic.

Line 35 avoids the division by zero (which would give a syntax error) and in the absence of an 'else' in this basic, C is set to an extreme value by default. 










Comments

  1. My solution on paper with algebra!:
    x+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

    ReplyDelete
  2. Thank you so much for this. I didn't think this question could be solved this way.

    ReplyDelete
    Replies
    1. yep! and for completeness, my python solution to bruteforce it:

      # 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))

      Delete

Post a Comment

Popular posts from this blog

ZX81 reversible internal 16k upgrade

T his post is an upvote for Tynemouth Software's  ZX81 reversible Internal 16K RAM upgrade . Their instructions are easy enough for even me to follow and don't involve cutting tracks. This is the ZX81 I've had out on display and used whenever I wanted to. It's an issue 1 and was probably a kit judging by some very untidy assembly. It has a ZX8-CCB  composite video mod and an external keyboard fitted. On board it has two 1k x 4-bit chips.  The ZX81 originally came with 1k on board. Thanks to a trick with compressing the display in ram, that was enough to type and run a small program but you soon felt the limitations. Back in the early 80s, the solution was a 16k ram pack which plugged into the back[1] and this is the way I've been using this particular machine. These ram packs are notorious for 'ram pack wobble'. Even if fastened into place, you can still randomly find your work disappearing. This is a very reliable solution using a more modern 32k chip (half

Driving NeoPixels with Z80

I 've long been thinking about a version two   RC2014 LED matrix module . I've had a matrix with a MAX 7219 on a module. It's a nice enhancement. But there's only so much you can do with a single-colour LED array right? Wouldn't it be cool to have RGB LEDs?  At Liverpool MakeFest I saw a wall-sized ping-pong ball NeoPixel display and picked up some NeoPixels with the intention of making one. Possibly driven by my RC2014.  I enjoy learning about protocols and have had some SPI devices working with the RC2014 - bit-banging SPI works really well because it doesn't care about timing. NeoPixels really do care about timing though. From Adafruit's web page about their 8x8  NeoPixel matrix: If there's one thing I want to get across in this blog post, it's don't just accept what you're told . Question everything. Learn about what's going on and find out why you're being told something isn't possible. Get creative with workarounds. I'

Making new ROMs for the Vic20 / Vicky Twenty

M y Vicky Twenty is very nearly complete.  As things stand, the board and every single component is new*. The processor and VIAs are newly-manufactured (W65C02 and W65C22).  Obviously the Vic1 chip isn't manufactured today, but there is 'new old' stock about. I have been able to buy a Vic 1, date code 1987 (which seems very late). It obviously hasn't been in a computer before, passes the acetone test and works. The same goes for two of the ROMs - character and BASIC. But I haven't been able to buy a new-old Kernal ROM (901486-07). I am able to borrow one - all of the boards I have, have this particular ROM socketed. I don't know whether all of this indicates that the Kernal has proved less reliable than the other two. I recently bought a TL866 for another project. Of all the retro-computing hardware things I've had to learn to do, making ROMs has been one of the simplest. So far, everything has been very easy and worked first time.  I'm not sure that it&