Project Euler with Befunge
Problem 052: 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.
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-|
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/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)|