Inspired by There, I fixed it (with rope), There, I fixed it (with Tape), There, I broke it (with scissors)
Given a string with characters from a-z
or A-Z
(whichever you prefer), turn missing letters into numbers and make them explode.
Example
Input: abcafabc
Output: a12344321c
Why?
1) Find the missing letters (only going forward in the alphabet): abca(bcde)fabc
2) Replace them with the number of missing letters: abca4fabc
3) Replace the number with
- Itself twice if it's even
- Itself + 1 if it's odd
In this case: abca44fabc
4) Explode those numbers outwards replacing any letters: a12344321c
Challenge Rules
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
ab
,aa
,aaa
, etc.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.
General Rules
- 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.
Test cases:
Input : 'abcdefgklmnopqrstuvwxyz'
Output : 'abcd1234321nopqrstuvwxyz'
Input : 'abdefgjkl'
Output : 'a121ef1221kl'
Input : 'xyzaz'
Output : '20212223242423'
Input : 'abceghij'
Output : 'ab12221hij'
Input : 'zrabc'
Output : 'zrabc'
abcefg
ground zero (represented byHERE
would beabcHEREefg
\$\endgroup\$acca
? \$\endgroup\$aeae -> 355553
(if that is correct) \$\endgroup\$abcfghabceazabcazabcefghabcfabcd
\$\endgroup\$