Given a string with characters from
A-Z (whichever you prefer), turn missing letters into numbers and make them explode.
1) Find the missing letters (only going forward in the alphabet):
2) Replace them with the number of missing letters:
3) Replace the number with
- Itself twice if it's even
- Itself + 1 if it's odd
In this case:
4) Explode those numbers outwards replacing any letters:
Explosions can't exceed the boundaries of the string
ae -> 343(3 letters are missing but since 3 is odd, it's been replaced by 4)
Numbers can be greater than 9
az -> 23242423(24 letters are missing and since 24 is even, it's repeated twice)
You can have multiple explosions
abcefghijmnop -> ab121fghi1221nop
Multiple explosions can overlap, take the sum of the number when they do
abceghij -> abc(2)e(2)ghij -> ab12(1+1)21hij -> ab12221hij
It's possible that no explosions occur, in that case simply return the string
No explosions between
You are allowed to take the input in any reasonable format. Can be a single string, string-array/list, character-array/list, etc. Output has the same flexibility.
You are allowed to use lowercase and/or uppercase any way you'd like. This applies both to the input, output.
- This is code-golf, so the shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-golfing languages.
- Standard rules apply.
- Default Loopholes are forbidden.
- If possible, please add a link to a test for your code, preferably Tio.
- Also, please add an explanation if necessary.
Input : 'abcdefgklmnopqrstuvwxyz' Output : 'abcd1234321nopqrstuvwxyz' Input : 'abdefgjkl' Output : 'a121ef1221kl' Input : 'xyzaz' Output : '20212223242423' Input : 'abceghij' Output : 'ab12221hij' Input : 'zrabc' Output : 'zrabc'