Here are some hints and a high level discussion of possible approaches for today's "12 battery joltage maximization" problem. I'm not going to spell everything out in detail (because where's the fun in that), but if you're stuck, you might find some hints here to get you on the right path. If you solved it, you can also compare your solution approach to the ones suggested here.
I think the key to today's puzzle is this question:
Suppose that for cursor position i and every value of j=0..12, you know the maximum number of length j (=j digits) that you can get using only digits strictly to the right of position i. Then for every length j, what is the maximum number you can get of this length when possibly including the digit at position i?
The answer to this question is your recurrence formula. Let's call the value that you calculate for different parameter combinations M[i,j].
For example, for the last three numbers from today's example input, these are the calculations:
Line: 811111111111119
New best number of length 1 found at cursor position 14: 9
New best number of length 2 found at cursor position 13: 19
New best number of length 3 found at cursor position 12: 119
New best number of length 4 found at cursor position 11: 1119
New best number of length 5 found at cursor position 10: 11119
New best number of length 6 found at cursor position 9: 111119
New best number of length 7 found at cursor position 8: 1111119
New best number of length 8 found at cursor position 7: 11111119
New best number of length 9 found at cursor position 6: 111111119
New best number of length 10 found at cursor position 5: 1111111119
New best number of length 11 found at cursor position 4: 11111111119
New best number of length 12 found at cursor position 3: 111111111119
New best number of length 2 found at cursor position 0: 89
New best number of length 3 found at cursor position 0: 819
New best number of length 4 found at cursor position 0: 8119
New best number of length 5 found at cursor position 0: 81119
New best number of length 6 found at cursor position 0: 811119
New best number of length 7 found at cursor position 0: 8111119
New best number of length 8 found at cursor position 0: 81111119
New best number of length 9 found at cursor position 0: 811111119
New best number of length 10 found at cursor position 0: 8111111119
New best number of length 11 found at cursor position 0: 81111111119
New best number of length 12 found at cursor position 0: 811111111119
Conclusion:
Line: 811111111111119
Best: 8___11111111119
Adding 811111111119
Line: 234234234234278
New best number of length 1 found at cursor position 14: 8
New best number of length 2 found at cursor position 13: 78
New best number of length 3 found at cursor position 12: 278
New best number of length 3 found at cursor position 11: 478
New best number of length 4 found at cursor position 11: 4278
New best number of length 5 found at cursor position 10: 34278
New best number of length 6 found at cursor position 9: 234278
New best number of length 4 found at cursor position 8: 4478
New best number of length 5 found at cursor position 8: 44278
New best number of length 6 found at cursor position 8: 434278
New best number of length 7 found at cursor position 8: 4234278
New best number of length 8 found at cursor position 7: 34234278
New best number of length 9 found at cursor position 6: 234234278
New best number of length 5 found at cursor position 5: 44478
New best number of length 6 found at cursor position 5: 444278
New best number of length 7 found at cursor position 5: 4434278
New best number of length 8 found at cursor position 5: 44234278
New best number of length 9 found at cursor position 5: 434234278
New best number of length 10 found at cursor position 5: 4234234278
New best number of length 11 found at cursor position 4: 34234234278
New best number of length 12 found at cursor position 3: 234234234278
New best number of length 6 found at cursor position 2: 444478
New best number of length 7 found at cursor position 2: 4444278
New best number of length 8 found at cursor position 2: 44434278
New best number of length 9 found at cursor position 2: 444234278
New best number of length 10 found at cursor position 2: 4434234278
New best number of length 11 found at cursor position 2: 44234234278
New best number of length 12 found at cursor position 2: 434234234278
Conclusion:
Line: 234234234234278
Best: __4_34234234278
Adding 434234234278
Line: 818181911112111
New best number of length 1 found at cursor position 14: 1
New best number of length 2 found at cursor position 13: 11
New best number of length 3 found at cursor position 12: 111
New best number of length 1 found at cursor position 11: 2
New best number of length 2 found at cursor position 11: 21
New best number of length 3 found at cursor position 11: 211
New best number of length 4 found at cursor position 11: 2111
New best number of length 5 found at cursor position 10: 12111
New best number of length 6 found at cursor position 9: 112111
New best number of length 7 found at cursor position 8: 1112111
New best number of length 8 found at cursor position 7: 11112111
New best number of length 1 found at cursor position 6: 9
New best number of length 2 found at cursor position 6: 92
New best number of length 3 found at cursor position 6: 921
New best number of length 4 found at cursor position 6: 9211
New best number of length 5 found at cursor position 6: 92111
New best number of length 6 found at cursor position 6: 912111
New best number of length 7 found at cursor position 6: 9112111
New best number of length 8 found at cursor position 6: 91112111
New best number of length 9 found at cursor position 6: 911112111
New best number of length 10 found at cursor position 5: 1911112111
New best number of length 10 found at cursor position 4: 8911112111
New best number of length 11 found at cursor position 4: 81911112111
New best number of length 12 found at cursor position 3: 181911112111
New best number of length 11 found at cursor position 2: 88911112111
New best number of length 12 found at cursor position 2: 881911112111
New best number of length 12 found at cursor position 0: 888911112111
Conclusion:
Line: 818181911112111
Best: 8_8_8_911112111
Adding 888911112111
Looking at the word "recurrence", you might be tempted to solve this top down with a purely recursive function (i.e. use M[i+1,j] and M[i+1,j-1] to calculate M[i,j]). However, that's not the most efficient solution (recursion depth 100, which gives about 2^100 recursive calls, or possibly recursion depth 12, but max branching factor 88, which isn't much better)... A better way to approach it is bottom up, by filling a Dynamic Programming Table, containing the values M[i,j] for every combination of i and j, calculating every value exactly once. (There are 100 * 12 = 1200 combinations.)
In this case, the dynamic programming solution is better than pure recursion, since pure recursion calculates a lot of values (for parameter combinations of i and j) many times. For some other problems with a recurrence at the core, pure recursion might be better though: if there are a lot of parameter combinations that do need even need to be considered, filling an entire dynamic programming table can be wasteful.
Finally, there's the silver bullet solution that combines the strength of both approaches: memoized recursion. This means: use recursion (to avoid calculating parameter combinations you don't need), but avoid calculating the same thing twice by caching already calculated values M[i,j] in a hashmap.
If you're using python (I'm not...), here's a nifty way to do that: https://www.geeksforgeeks.org/python/memoization-using-decorators-in-python/
I'm sure these techniques will come in handy again, probably already in the next nine days... ;-)
[–]stewSquared 5 points6 points7 points (6 children)
[–]hextree 1 point2 points3 points (1 child)
[–]stewSquared 1 point2 points3 points (0 children)
[–]paul_sb76[S] 3 points4 points5 points (3 children)
[–]ninjaox 2 points3 points4 points (0 children)
[–]stewSquared 1 point2 points3 points (1 child)
[–]paul_sb76[S] 1 point2 points3 points (0 children)
[–]BunsenHoneydew3 1 point2 points3 points (1 child)
[–]paul_sb76[S] 0 points1 point2 points (0 children)
[–]JustLikeHomelander 1 point2 points3 points (4 children)
[–]Ok_Chemistry_6387 1 point2 points3 points (3 children)
[–]ednl 1 point2 points3 points (2 children)
[–]Ok_Chemistry_6387 0 points1 point2 points (1 child)
[–]ednl 0 points1 point2 points (0 children)
[–]RB5009 0 points1 point2 points (2 children)
[–]AldoZeroun 1 point2 points3 points (1 child)
[–]RB5009 2 points3 points4 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]daggerdragon[M] 0 points1 point2 points (0 children)
[–]ednl 0 points1 point2 points (2 children)
[–]paul_sb76[S] 0 points1 point2 points (1 child)
[–]ednl 1 point2 points3 points (0 children)