Monday 24 February 2014

Nostalgic numbers - fun with numerical anagrams

As I battled to dry the tears running down my wrinkled face with facts about my latest age, there was a fleeting moment when I thought 'hey, when you double 26 you reverse its digits, don't you?'. Answer: uhh.... no (exercise: prove this). But I started to wonder whether any two-digit numbers did have this property, that switching the digits results in a number that's twice the original. Have a go if you like and see what you find.

The answer this time? Well, it's also 'uhh... no', but a slightly more impressive one. To prove it, notice that if our number is written with two digits, xy, then it has value 10x + y. We'll write (x,y) rather than xy to avoid confusion with multiplication. We want (y,x) to be twice (x,y), which means the following property must hold:

10y + x = 2(10x + y) , so
10y + x = 20x + 2y,
8y = 19x,
y = 19/8 x.

We can see that x needs to be divisible by 8, or y won't be a whole number. So x must be at least 8, but then y needs to be at least 19. What does it mean for a digit to be greater than 9? Not much! There can't be any pairs of digits (x,y) that satisfy this equation. Bam.

[I initially wrote a different proof of the above, which I'll post as a comment below.]

On first glance, that's a shame, but on second - not really. There's something much more interesting going on behind the scenes, namely that if we choose to work in a different base, it is possible to find solutions. Quick base primer: usually when we write a number, it's code for adding powers of ten together to represent a quantity, for example

217 = 2*100 + 1*10 + 7*1.

But we don't have to use ten as the base: for instance, since

217 = 4*49 + 3*7 + 0*1,

we could write the same quantity as 4307, which we call the 'base 7' representation of the number. 'Binary' refers to the base 2 representation; 21710 in binary would be 110110012. Mathematicians don't like numerical statements that are dependent on an arbitrary label such as the number's base representation, unless that notion can be generalised to all bases. If we had found solutions, but only in base 10, we would still be missing infinitely many others!

Let's get ourselves into a more general mood here. In base k, the number with digits (x,y) has value kx + y, and we're looking for numbers with the property that

ky + x = 2(kx + y).

Expand this out, rearrange (as before) and we're left needing

y = (2k - 1)/(k - 2) x.

The problem is now just a matter of finding the values of k, x and y that solve this equation. To get the ball rolling, one solution is (k,x,y) = (5,1,3), i.e. in base 5, the number written '31' is twice the number written '13'. Indeed, we find that

135 = 1*5 + 3 = 810 and
315 = 3*5 + 1 = 1610 = 2*810.

Since I initially had decrepitude in mind when thinking about these, I've decided they should be called 'nostalgic pairs', which to me evokes images of the larger number gazing into the mirror (calibrated to a certain base!) and seeing its old self, half its current age, reflected back. The table shows the lower halves of a few more nostalgic pairs and a general rule for constructing the rest. The rule is fairly easy to deduce once you notice a pattern, and you can check it's correct by plugging it into the above formula.

kxyBase 10 representation
5138
82521
113740
144965
............
3n+2n2n+1(3n+1)(n+1) [any base]

So the first few nostalgic pairs, expressed in base 10, are {8,16}, {21,42}, {40,80} and {65,130}. Although 130 is three digits in base 10, in base 14 it's only two: 9414. You can see that the list goes on: there are infinitely-many two-digit nostalgic numbers and the second digit and base are entirely determined by the first digit. Note that we can't construct, say, the digits (2x,2y) from (x,y) in this table and have a solution for the same base, since 2y would be (4n + 2), larger than the base it's supposed to be written in. Similarly we can never divide (x,y) by some constant to find a smaller pair of digits, because if a number were to divide x = n, it would always leave a remainder of 1 when dividing y = 2n + 1. There's a little more work involved in proving the above ratios between x and y are the only solutions and it's more fiddly than interesting, so I'll omit it and leave it for you to do if you're really keen.

It gets better! Why stop at doubling numbers to reverse their digits? What about numbers that flip when you triple them, quadruple them, and so on? They also exist, also in infinite quantities, and although the situation is similar there's a few extra things to say about them (as well as more cute names to give them, of course), which I'll leave for another week. I'm also pleased to report the first three-digit nostalgic pair, which took me a little while, but starts with the base 5 quantity:

1435 = 4810, which is double 3415 = 9610.

Awesome.

1 comment:

  1. [Here's the first proof I wrote that there are no base 10 solutions. I chose it because in my opinion it's more intuitive to someone with a casual maths background, but then I replaced it because it's a bit scrappy and the new version acts as a warm-up to what comes later. If you have an opinion on which is better, please let me know!]

    With a little thought, you can shave away all but a handful of cases that need checking. For starters, doubling a two-digit number involves either doubling its first digit (if the second digit is less than 5) or doubling it and adding one. The second digit must equal one of these options, since we require it to become the first digit after the number is doubled. In other words, the digits (x,y) need to have the form:

    (n,2n) if 2n < 5 or
    (n,2n+1) otherwise.

    Cycling through n, this gives us only a few numbers to check: 12, 24, 25, 37, 49, and none of those is a solution to our problem. We could have been a bit cleverer and noticed, for instance, that the first digit has to be even (otherwise the reversed form will be odd - therefore not twice the original), but there comes a point at which deducing and applying another rule takes longer than just checking all the cases that are left!

    ReplyDelete