Every now and again, I'll encounter a large string of alphabetical text encoded as numbers from 1-26. Before I knew that I could just google a translator online, I had to personally, painstakingly copy and paste the entirety of the encoded text into a text document and translate it myself.
Thankfully, I did know about find-and-replace features, which I used to search for all copies of each number and convert them to their corresponding characters. Only one problem... If you do this in numerical order, it will come out garbled.
This is because the single digit numbers used to encode a-i also appear as part of the remaining two digit numbers encoding j-z. For example,
26 should decode to
z, but since both 2 and 6 are less than 26, we decode those first.
Note also that for
20, there is no conversion for
0, so we end up with
Given a string of alphabetical characters (
abcdefghijklmnopqrstuvwxyz), output the result of converting to numbers and back again using the algorithm described above. You may assume input is all lowercase or all uppercase. This is code-golf, so shortest code in bytes wins.
Important: You may not zero index.
Full conversion list:
a: a b: b c: c d: d e: e f: f g: g h: h i: i j: a0 k: aa l: ab m: ac n: ad o: ae p: af q: ag r: ah s: ai t: b0 u: ba v: bb w: bc x: bd y: be z: bf
xyzzy => bdbebfbfbe caged => caged jobat => a0aebab0 swagless => aibcagabeaiai