solved p40, using a fairly simple approach; build up the string until there's enough digits, then reference the various indices, both operations of which are ~ O(N)