How do I finish coding this problem?
Mostrar comentarios más antiguos
I am coding a problem from project euler and its problem 52.
I cant seem to go any further and i need help finishing up the problem and making it work on MATLAB.
Problem: 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.
My code: MAIN
int begin=1;
bool found=false;
int result=0;
while(not(found))
begin= begin*10;
for i = 0: begin*10/6
found=true;
for j=2:6
out1 = permuted(i,j*i);
if out1, found = false ; break , end
end
if found, result=i; break , end
end
end
function out1 = permuted(x,y)
% ??? int arr[] =[10];
temp = y;
while (temp>0)
arr(mod(temp,10)) + 1;
temp = temp / 10;
end
temp = x;
while(temp > 0)
arr(mod(temp/10)) - 1;
temp = temp / 10;
end
for i=0;10;
if arr(i) ~= 0
out1 = false;
end
end
out1=true;
end
I dont know what else to do can comeone please help me finish the code to complete the problem.
2 comentarios
Jan
el 13 de Mayo de 2019
I've formatted your message to improve the readability. Some lines of code are not meaningful:
int begin=1; % Not Matlab
bool found=false;
int result=0;
int arr[] =[10]; % Not Matlab
arr(mod(temp/10)) - 1; % This does nothing
for i=0;10; % You mean: for i = 1:10
if arr(i) ~= 0
out1 = false;
end
end
out1=true; % This overwrites out1 in every case
Frank Pinedo
el 13 de Mayo de 2019
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Introduction to Installation and Licensing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!