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 as we would need.
defghijkl(length 9), so we fill this with
qr(length 2), so we fill this with
uvwxy(length 5), so we fill this with
- The difference only applies forward, so no tape between
- It is possible to have multiple of the same adjacent letters like
- 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
- It is possible no
TAPEis necessary, in which case the input remains unchanged.
- 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.
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"