I hinted at some optimization a couple of replies ago, but the reactions were such that the set of people interested probably equals the empty set.
And as Carey remarked, it is a waste of time trying to be smart for such a small problem.
But optimizing is sometimes more interesting than the problem itself. So here goes.
Let S0 be the product of the first 13 digits of, what Dana called, bigNumber.
So, S0 = d0 * d1 * d2 * ... * d12.
The product of the next 13 digits, S1, is: d1 * d2 * ... * d12 * d13. or: S1 = S0 * d13 / d0.
And so is S2 = S1 * d14 / d1, et cetera.
This resembles an iteration.
1) suppose that bigNumber does not contain any '0''s. We could then say:
Now, this 'alpha' is of the form d(i + 13) / d(i), so how to get this dynamic factor into the longstrean?
To
test that all this is correct, we could use:
2) now, unfortunately, bigNumber does contain a lot of '0', totally ruining the above scheme.
Can you think of a simple way to deal with this problem, at the same time optimizing the excersize even further?
I must confess that for this, I used plain old
java 7, since java 8 really got complicated.
Well, happy extended puzzling!