Permuted multiples
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.
Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.
This problem is straight forward and there is no big algorithm that I have used. I have used a series of if statements to get the solution. The only thing I want to mention is that, we will start with checking if all the digits of the multiple of 6(
i*6
) are present in the given number(i
). Then 5(i*5
), 4(i*4
), 3(i*3
), 2(i*2
). Using 6 will reduce the number of iterations and thus reduces the execution time.I will not explain the program, I have left that part for you to understand because it is not very complicated. Remember that I have added the links to the inbuilt functions used in the program.
Program
As always you can download the source code from Github Gist pep52.py
Output
Summary
I think this problem has been designed to make us use the
while
loop. This is a very basic problem. You can also find a solution in mathematical point of view, to improve the performance of the code. Anyways I have used a direct and simple approach to solve this problem and also the execution time is pretty satisfactory. As always you can comment in the comment box below, if you have any doubt or haven't understood anything. I will be very happy to help you.
Please do comment in the comment box below if you have found any typo or have a better program or have a different solution or have a suggestion. I will be glad to see each of them.
You can also contact me.
Thank you. Have a nice day😃!