How do I finish coding this problem?
이전 댓글 표시
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
Jan
2019년 5월 13일
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
2019년 5월 13일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!