Challenge:
Given a string only containing upper- and/or lowercase letters (whichever you prefer), put tape
horizontally to fix it. We do this by checking the difference of two adjacent letters in the alphabet (ignoring wrap-around and only going forward), and filling the space with as much TAPE
/tape
as we would need.
Example:
Input: abcmnnnopstzra
Output: abcTAPETAPETmnnnopTAstTAPETzra
Why?
- Between
c
andm
should bedefghijkl
(length 9), so we fill this withTAPETAPET
; - Between
p
ands
should beqr
(length 2), so we fill this withTA
; - Between
t
andz
should beuvwxy
(length 5), so we fill this withTAPET
.
Challenge rules:
- The difference only applies forward, so no tape between
zra
. - It is possible to have multiple of the same adjacent letters like
nnn
. - 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, and
TAPE
. - It is possible no
TAPE
is necessary, in which case the input remains unchanged.
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-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link to a test for your code.
- Also, please add an explanation if necessary.
Test cases:
Input: "abcmnnnopstzra"
Output: "abcTAPETAPETmnnnopTAstTAPETzra"
Input: "aza"
Output: "aTAPETAPETAPETAPETAPETAPEza"
Input: "ghijk"
Output: "ghijk"
Input: "aabbddeeffiiacek"
Output: "aabbTddeeffTAiiaTcTeTAPETk"
Input: "zyxxccba"
Output: "zyxxccba"
Input: "abccxxyz"
Output: "abccTAPETAPETAPETAPETAPExxyz"
Input: "abtapegh"
Output: "abTAPETAPETAPETAPETtaTAPETAPETAPETApeTgh"
Input: "tape"
Output: "taTAPETAPETAPETApe"
ab[TAPETAPETAPETAPET]TA[TAPETAPETAPETA]PE[T]gh
(added the[]
to make it more readable). \$\endgroup\$