Coding Can Make your Life Easy
Few days back, one of my close friend gave me a puzzle to solve. The puzzle was something like this -
A number has six different digits. If the last digit is moved to the front, the new number formed is five times the original number.
It was something that I was supposed to solve using paper and pen but after trying hard for hours and wasting 5 pages of my notebook, I decided to go with a different approach.
WHY NOT USE CODING TO FIND THE SOLUTION ?
So, before jumping on the coding part, let’s think about the logic and what algorithm we can use to solve it.
Question says it’s a 6 different digit number, so that means our number will look something like this:- abcdef . Now, we move f to the start and our new number will look something like this:- fabcde , which is 5 times the original number that means:-
fabcde = 5*abcdef.
Ok good, now we have our equation set. Let’s brainstorm more and decide on the correct range of numbers. We know that as it’s a 6 digit number, starting number will be 100000. What about the end number, as after modification, our final number is also a 6 digit number, we know that end range number will be less than 200000 as 5 times of 200000 is a seven digit number.
So we know the number we want lies between the range (100000, 200000).
The last part left now is to loop over this range and try out all numbers between range and check after moving last digit of the number, the new number formed is 5 times the original number or not and also check whether all digits of the numbers are different or not. For sure, one number will satisfy the condition and that will be answer.
I know you all are waiting to know what is the answer, so here it is, the answer is 142857.
I am also pasting the code that I used to get this number for reference. The code is in c++.
Also if anyone is able to come up with a solution that involves another approach or a maths formula that would help us to solve it using by hand then please let us all know in the comments section.