How do I finish coding this problem?
Show older comments
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 Comments
Jan
on 13 May 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
on 13 May 2019
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!