*Spoiler for last week’s fivethirtyeight.com Riddler Classic:*

From Joseph Converse, a puzzle of digital manipulation:

Imagine taking a number and moving its last digit to the front. For example, 1,234 would become 4,123. What is the smallest positive integer such that when you do this, the result is exactly double the original number? (For bonus points, solve this one without a computer.)

# One way

Write the number (call it ) as , where ; for instance, for 1,234, and . Let be the number of digits in ; then the number resulting from moving the last digit to the front is . We want .

Solving, we get . Now, 19 is prime and so isn’t a multiple of 19, and therefore must be, that is, .

Going ahead and doing the long division ― that is, dividing 100, 1000, 10000… by 19 until a remainder of 2 is found ― we get ; . That has 16 digits, so won’t work; will give us a 17-digit , though. So the smallest number that works is .

# Another way

We require to have the same number of digits as , and that means the first digit of can’t be 1. So let’s try making it 2. Then that’s also the last digit of .

Now, the last digit of is 4, which is also the second to last digit of . And then the second to last digit of is 8, which must be the third to last digit of . Then the third to last digit of is 6, with a carry. That means the fourth to last digit of is 6 and the fourth to last digit of is 3, with a carry.

And so on, until we reach a place where the digit of is 1 and is 2 without a carry. Stop there. Follow that procedure and you get as before.

Except we don’t know that this is the smallest answer. We need to do the same with last digit of running from 3 to 9. In fact (and as you’d expect having seen the other method) this is the smallest.

I’m rather surprised the second way didn’t occur to me sooner; it seems a good deal more obvious in retrospect. Then again, had I done it first I think I might’ve looked at the size of the result and been unconfident I hadn’t overlooked something that might give a smaller answer. The first method confirms it and makes it more clear, I think, that this really is the minimum. It also provides the insight that the answer is not just a mysterious sequence of digits but is connected with the decimal representation of 1/19.

# Triple?

Instead of moving the digit to get multiplication by 2, what about by 3? Or by generally? Adapting either method, one finds moving the last digit of 1034482758620689655172413793 to the front gives triple that number. For quadrupling we get a much smaller answer: 102564 = 410256/4. For quintupling we encounter for the first time the necessity of checking all possible last digits, not just the minimum one: Using 5 for the last digit we find 102040816326530612244897959183673469387755, but with 7 we get 142857! This is related to the fact that if you try the first method, you need , and 49 is *not* prime, so when we need rather than .

Here’s a table for = 1 through 9. I am glad the Riddler puzzle didn’t ask for 6 (by hand)… I did these with a spreadsheet.

1 | 1 |

2 | 105263157894736842 |

3 | 1034482758620689655172413793 |

4 | 102564 |

5 | 142857 |

6 | 1016949152542372881355932203389830508474576271186440677966 |

7 | 1014492753623188405797 |

8 | 1012658227848 |

9 | 10112359550561797752808988764044943820224719 |

# All your base

Another generalization of the original puzzle is to do it in base instead of base 10. There’s no solution in binary, as you can figure out by trying to adapt either method above, or just by noting that doubling a number in binary means appending a 0 to the right end, so you can’t double a number and get a number with the same number of binary digits (bits). In base 3, starting with final digit 2 for , the final digit for is 1 with a carry of 1; 1 for the next digit of gives 0 for the next digit of with a carry; 0 for gives 1 for ; 1 for gives 2 for and we’re done: . In decimal, that’s 32 and 64. (In higher bases we need to check last digits from 2 to .) Alternatively, we want and so require . works and then . So with , and .

In all bases from 3 through 10:

3 | 1012 |

4 | 102 |

5 | 13 |

6 | 1031345242 |

7 | 103524563142 |

8 | 25 |

9 | 10467842 |

10 | 105263157894736842 |

*Edit to add:*

And if this Python script is bug free, then

is the smallest base 15 number which is multiplied by (decimal) 10 when the last digit is moved to the front. At 148 digits, it’s the longest such number for all bases up to 16 and all factors up to (base-1).