How can I find this six digit number?
Show older comments
Find a six digit number in which the first digit is one more than the third, the second digit is one less than the fourth, the fifth digit is one less than the third, and the sixth digit is one more than the fourth. The sum of the second and third digits equals the first. The sum of all digits is thirty. This is a Mensa Challenge Mat-lab deliverable.
Accepted Answer
More Answers (2)
Joseph Cheng
on 10 Sep 2015
Edited: Joseph Cheng
on 10 Sep 2015
1 vote
Where are you getting stuck? This is a simple linear algebra question (Ax=B) hint use mldivide() or the shortcut \. You have 6 unknowns and 6 conditions.
1 Comment
Marjorie Sanford
on 10 Sep 2015
Image Analyst
on 11 Sep 2015
Marjorie, I get the feeling that some of the other answers are too complicated for you. If you want to do a not-too-clever, but dumb, brute force test, you can do this:
% Find a six digit number in which the first digit is one more than the third,
% the second digit is one less than the fourth,
% the fifth digit is one less than the third,
% and the sixth digit is one more than the fourth.
% The sum of the second and third digits equals the first.
% The sum of all digits is thirty.
for d1 = 0:9
for d2=0:9
for d3=0:9
for d4=0:9
for d5 = 0:9
for d6=0:9
c1 = d1==d3+1;
c2 = d2 == d4-1;
% and so on for the c3-c6 conditions.
% Now check if all conditions are true
if c1&c2&c3&c4&c5&c6
finalNumber = d1*100000 + d2*10000+...
break
end
end
end
end
end
end
end
I've left some things for you to finish there. It's really a straightforward but not too clever or efficient way but it's easy to understand and should run in much less than a second.
2 Comments
Marjorie Sanford
on 14 Sep 2015
Image Analyst
on 14 Sep 2015
Think: what does each digit represent? Do you really want to multiply each digit by one hundred thousand? In the number 724681, does the 8 represent 100,000 (like you have it) or does it represent the 10's place and should be multiplied by 10 instead of 100,000?
Categories
Find more on MATLAB 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!