Contents
raw puzzle
Problem 52

It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.

Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.

Solution

The obvious brute force solution can be implemented easily and for the scope of the problem, optimizations are not necessary. However, for \(x<10\), it is clear that no solution exists. The second observation is, that \(6x\) grows much faster than \(2x\) or even \(5x\). Looping in reverse makes the loop break earlier. Another obvious observation is that the digit count, or the length \(L(m)\) of all numbers must be equal, which means \(L(x)=L(2x)=L(3x)=L(4x)=L(5x)=L(6x)\), but converting a number to string and split this number into aset, which then is sorted is fast enough to come up with the following implementation:

from itertools import count
def solution():
 for x in count(start=10):
   digits = sorted(str(2 * x))
   if all(sorted(str(x * k)) == digits for k in range(6, 2, -1)):
     return x

The result is interesting, as \(x\) is the repeating part of \(\frac{1}{7}\) and the coefficients 2, 3, 4, 5 and 6 create permutations of it.