# Dave switched the calculator keys

My calculator has the usual number keys:

0123456789

Dave swapped two number keys around, and won't give it back until I work out which keys he's swapped.

I can give him one sum, using one or more of the basic operators +−÷×, and he will tell me the result on the screen after he presses the equals key.

What sum should I give, so that I will know what keys were swapped when he tells me the result? Or is this simply not possible?

Perhaps the most obviously correct way to do this is

123456789 + 123456789

because

You can halve the result, producing the number that the key sequence 123456789 corresponds to (as the key swap will affect both halves equally), and then you'll know which digit each of the keys from 1 to 9 corresponds to (and can determine 0 by elimination). This actually works for any permutation of the number keys, not just swaps.

• Excellent. The result couldn't be clearer IMO. – rybo111 Apr 9 '17 at 21:13

The easiest way would be to

not use the operator keys at all. For example "1234567890". Then if Dave tells you "1264537890" you know that he swapped 3 and 6.

But if that is not allowed,

"123456789+0". This should be 123456789, and if Dave tells you that it is indeed 123456789, then he swapped 9 and 0. Otherwise it should be easy to find which keys he swapped.

• The first example is not allowed as it needs "one or more". Please explain your other example. – rybo111 Apr 9 '17 at 12:45
• For example, if the result is "120,456,792" - what keys were swapped here? – rybo111 Apr 9 '17 at 12:53
• 0 and 3. In general, swapping 0 and n changes the result by n.(10^(9-n)-1) and if a,b are nonzero then swapping a and b changes the result by (a-b)(10^(9-a)-10^(9-b)) and no two of these deltas are equal. – Gareth McCaughan Apr 9 '17 at 12:55
• May I suggest changing your second answer to "1234567890+0"? By having a 0 in the first number you guarantee that the response can be immediately understood. – ThunderGuppy Apr 10 '17 at 20:45
• @gkubed What if 7 and 0 were swapped? – Rosie F Apr 11 '17 at 18:50

## My Theory is..

1234567890 + 0
If no keys are switched:
= 1234567890

.

If any two non zero numbers are switched, it will be very visible:
1234567890 + 0 = 1294567830
therefore 3<=>9

Special Cases if result does not end in a 0
if second last number is 9,
....0<=>x where x < 5
....0 was swapped with a number less than 5, half the final number to find x
....e.g ( 1204567893 + 3 = 1204567896 ) (6/2 = 3 = x)

otherwise
....0<=>x where x >= 5
....0 was swapped with a number greater than or equal to 5, add 10 to the final number and half it to find x ....e.g ( 1234507896 + 6 = 1234507902) ( (2+10)/2 = 6 = x)

Might be a little complicated, i'm not too sure, but its the first thing that came to my head...

First post (:

Here's a way to make use of both addition and multiplication, such that you can pretty much "read" the answer with no real follow-up calculations needed.

2 + 3*100 + 4*10000 + 5*1000000 + ... + 9*10000000000000000

If no keys were switched, you would get

9 08 07 06 05 04 03 02

If $n, m \geq 2$ were switched, you can just 'read' this from the number. E.g. $4$ and $6$ were switched:

9 08 07 04 05 06 03 02

If $n \geq 2$ and $1$ are switched, then the result consists of multiples of $n$ in decreasing order, but with $n*n$ replaced by $n$. E.g. suppose $4$ and $1$ were switched:

36 32 28 24 20 04 12 08

If the number looks nothing like the above, it means $0$ and $n \geq 0$ were switched. In this case:

If the number only has 14 digits, it will be 16 14 12 10 08 05 69 and this means 0 and 9 were switched.
If the number has 16 digits, then the second digit, plus one, is the one that was switched with 0.
E.g. if $4$ and $0$ were switched, you get 13 11 65 75 40 55 59 74. The second digit is $3$, so add $1$ and you get $4$.

My solution is similar to what others had put in principle but it was slightly different. My sum is:

$$9\times10^{2\times 9} + 8\times10^{2\times 8} + 7\times10^{2\times 7} ... 1\times10^{2\times 1} + 0\times10^{2\times 0} - (9\times 1,000,000,000,000,000,000 +8 \times 10,000,000,000,000,000 + 7 \times 100,000,000,000,000 + ... 1\times 100 + 0)$$

With the logic that, with no changes we're looking at:

$9,080,706,050,403,020,100 - 9,080,706,050,403,020,100$

Lets say Dave changed 2 and 8 so we get:

$$9,020,706,050,403,080,100 - 9,080,706,050,403,020,100 = 0,004,000,000,000,060,000$$ This result makes the two odd ones stick out nicely and you can just use the position of the smaller one and the difference to spot the solution.

Of course there is a difficulty if:

Dave has switched 1, 0 or both because this interferes with our first bit. >! If only 1 is changed then it isn't so hard. Switching 1 and 5 gives: $$5\times (9,080,706,010,403,020,500 - 9,080,706,050,403,020,100) = 0,000,000,030,000,002,000$$ But we know the positions which have been changed so can still work it out. If 0 was switched with 9 we get $$937146152681269000000000$$ Where the number of 0s at the end will correspond to the number which has been switched with 0. If 1 and 0 are switched you will get 0 (since $1^{0} = 1^{1}$)

I know it looks more complicated but I just preferred the answers coming out without as many other numbers in there.

EDIT: Just realised the question doesn't allow for using powers, so this method doesn't actually work

• In stead of saying $10^{2x9}$ you can simply say 1000000000000000000. – Stig Hemmer Apr 11 '17 at 8:10
• @StigHemmer I used both, the $9 \times 10^{2\times 9}$ is self referring so it positions itself correctly in the series regardless of what the buttons are. If we do $9\times 1,000,000,000,000,000,000$ we always get our "9" in that position whether it is actually a 9 or not. – Lio Elbammalf Apr 11 '17 at 8:22
• Oh. My bad. I didn't understand what you were doing. – Stig Hemmer Apr 11 '17 at 9:26