Given an input of a list of numbers in the format of a shorthand increasing integer sequence, output the sequence in full.
Shorthand increasing integer sequence format works by finding every number n with fewer digits than the number preceding it, m. With d as the number of digits in n, the last d digits of m are replaced with all the digits of n. Here's an example input:
123 45 6 7 89 200
Applying the replacement rule, we first turn 45 into 145 because 45 < 123:
123 145 6 7 89 200
Repeatedly applying the same rule, this becomes:
123 145 146 7 89 200
123 145 146 147 89 200
123 145 146 147 189 200
The sequence is now sorted (there are no numbers for which the rule applies), so this is the final output.
You may assume that
shorthand notation is always used when possible. For example, input will be
12 3
, never12 13
.numbers will never decrease while remaining the same number of digits. For example, input will never be
333 222
.applying the shorthand rule will never result in a number that is still less than the previous number in the sequence. For example, input will never be
123 12
.numbers will always be positive integers and never contain leading 0s (if using a string format).
the full, expanded sequence will never contain duplicate numbers. (However, the shorthand sequence might; ex.
10 1 20 1
->10 11 20 21
.)there will be at least one number in the input.
Input and output can be either lists/arrays of numbers/strings or a single string with elements separated by any non-digit.
Since this is code-golf, the shortest code in bytes will win.
Test cases, with input and output on alternating lines:
1 2 3 10 1 2 20 5 100 200 10 3 5 26 9 99 999 9999
1 2 3 10 11 12 20 25 100 200 210 213 215 226 229 299 999 9999
223 1184 334 441 5 927 2073 589 3022 82 390 5 9
223 1184 1334 1441 1445 1927 2073 2589 3022 3082 3390 3395 3399
5 10 5 20 5 30 5 40 5 50 5
5 10 15 20 25 30 35 40 45 50 55
7 8 9 70 80 90 700 800 900 7000 8000 9000
7 8 9 70 80 90 700 800 900 7000 8000 9000
42
42