Eugene Rabii wrote:I have to say, this is impressive!
I have reached the same code:
x = ( 2*(10^n) - 4 ) / 19
And it was a pleasure getting here!
Cheers, Eugene
-4? -2 surely?
My thinking runs this way:
2 * (10^n) + (x-2)/10 = 2x
2 * (10^(n+1)) + x - 2 = 20x
2 * (10^(n+1)) - 2 = 19x
x = (2 * (10^(n+1)) - 2 ) / 19
So, we just look for a value of n that makes x an integer ending with 2. The n vs (n+1) doesn't matter, but the -4 vs -2 will produce different answers.
OK, code time:
Results:
2, 10, 8
3, 105, 3
4, 1052, 10
5, 10526, 4
6, 105263, 1
7, 1052631, 9
8, 10526315, 13
9, 105263157, 15
10, 1052631578, 16
11, 10526315789, 7
12, 105263157894, 12
13, 1052631578947, 5
14, 10526315789473, 11
15, 105263157894736, 14
16, 1052631578947368, 6
17, 10526315789473684, 2
18, 105263157894736842, 0
So the answer is 105263157894736842. The check for the last digit being 2 turned out to be unnecessary, but I
think that's a coincidence.
ETA: In reading through Mike's solution, I see the -4 makes sense if you declare x to be the number without the final 2. Sorry about that!
I wonder if we can prove we don't have to check the final digit, as both Mike and I discovered?