Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Trivial riddle. Can you find out the formula?

My wife emailed this (quite trivial) riddle

My question is

Can you find a function from f: ℤ² → ℤ which does the job?

thank you for your attention

Update:

I like Ben's solution

I tried to go further extending to all integers (at least I HOPE so...)

The formula is even uglier than Ben's and uses Mathematica awful language

f[a_,b_]:=

(a - b) 10^Ceiling[Log[10,Abs[a+b]]]

+Abs[a+b]* If[a!=b,Sign[a-b],Sign[a]]

the IF..THEN..ELSE part is necessary to avoid zero result when the two numers are equal

The Ceiling is the Floor + 1 :)

some examples

f[12,3] = 915

f[3,12] = -915

f[12,12] = 24

f[-3,12] = -159

f[12,-3] = 159

f[-12,-3] = -915

Attachment image

4 Answers

Relevance
  • Ben
    Lv 6
    7 years ago
    Favorite Answer

    Others have already solved the riddle, but not provided the function. This is also easy, if a bit ugly. The point is that we need to have a way to find the number of digits of the sum. Let

    g(m,n)=number of digits in m+n,

    then clearly the desired function is

    f(m,n)=(m-n)*10^(g(m,n)) + (m+n).

    The number of digits of a positive integer is roughly the base-10 logarithm. Precisely,

    g(m,n)=\floor{ \log(m+n) } + 1.

    So, if you like, the function is

    f(m,n)=(m-n)*10^( floor(log(m+n))+1 ) + m+n

    EDIT: Er, I guess I don't know what to do if m<n. But you haven't given any such examples, so I guess this technically "does the job" :P

    EDIT 2: I like your extension! (But the ceiling is not the floor+1 when the argument is an integer, see e.g. your first example.)

  • Anonymous
    7 years ago

    The first 2 digits (from the right) are the sum of the 2 numbers.

    The Other digits are the difference between the 2 numbers.

    For Example:

    A) 9 + 8 = 117

    9+8=17, 9-8=1 ---> 117

    B) 15 + 3 = 1218

    15+3=18, 15-3=12 ---> 1218

  • fizixx
    Lv 7
    7 years ago

    Looks like you have:

    m + n = ABC...

    m + n = BC

    m - n = A

    => (m-n)(m+n) would be the 3+ digit result

    Example:

    9 + 8 = (9-8)(9+8) = (1)(17) = 117

  • 7 years ago

    subtract the second number from the first, and write it down. then append the sum of the two numbers

Still have questions? Get your answers by asking now.