Permuted multiples


Fork me on GitHub
2015-01-17

Problem 052: Permuted multiples

Description:

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:
55+>v>v>5+/>::103p55+*>55+/        :#v_$212pv
XX  :6/5 >  ::103p55+*^p30*g30+2%+55:<      :
XX  0:1:  v$_v#!:       /+55<*+55p311* <g21 <
XX  1p1p  1  >:55+%2+13g*13p^     >:12g^
  >^>^>^  >3g03g-   #v_12g1+:12p7-|
  ^*+55$_^#!`\g11:+1$<        @$$.<
Start
??
Pause
Reset
Output:
Stack:   (0)

Explanation:

To be a permutation all six numbers have to have the same digit count. So digitcount(x) == digitcount(x*6).

This for each number of digits only given for the numbers from 10^n to 10/6 * 10^n.
We perform the permutation check with an modified version of the algorithm used in problem-49 (product of all digits plus two). But we generalise the code to work with every number of digits.

And because we greatly limited the amount of numbers to search and the permutation test is pretty fast this is all we need to do (except run the code).


Interpreter steps: 18 887 060
Execution time (BefunExec): 2.92s (6.47 MHz)
Program size: 45 x 6 (fully conform befunge-93)
Solution: 142857
Solved at: 2015-01-17



made with vanilla PHP and MySQL, no frameworks, no bootstrap, no unnecessary* javascript