Your task
Given a numerical string or integer \$\ge 0\$ (which may have leading zeros), convert it to letters using the below rules.
Rules
Loop through the digits:
- If the digit is
0
or1
, combine it with the next digit and output that letter of the alphabet (0-indexed). - If the digit is
2
, combine with the next digit ONLY IF the next digit is between0
and5
(inclusive). Otherwise, outputc
(2nd letter of the alphabet, 0-indexed). - If the digit is
3
or more, output that letter of the alphabet (0-indexed).
Example
Our input is the number 12321
.
We loop through the digits:
1
: this is less than 2, so we keep this and wait for the next digit.2
: combine with the previous digit,1
, to get12
. Index into the lowercase alphabet (0-indexed) to getm
3
: this is more than 2, so we output the 3rd letter of the alphabet (0-indexed),d
2
: this is 2, so we check the next digit. It is less than 6, so we wait.1
: combine with the previous digit,2
, to get21
. Index into the lowercase alphabet (0-indexed) to getv
Our output is mdv
.
Test cases
Random
Input Output
132918 ncjs
79411 hjel
695132 gjfnc
800125 iamf
530987 fdjih
144848 oeiei
93185 jdsf
922846 jwieg
187076 shhg
647325 gehdz
Edge-cases
Input Output
0 a
1 b
25 z
26 cg
000 aa
123 md
0123 bx
1230 mda
12310 mdk
12345 mdef
00012 abc
Feel free to create your own test cases in this TIO of some ungolfed Python code.
Clarifications
- Everything must be 0-indexed
- You cannot ignore leading 0s (see the 5th and 6th edge-cases)
- If the last digit is 0, 1, or 2, and it has not already been used by the previous digit, output "a", "b", or "c" respectively (see edge-cases)
- This is code-golf, so shortest answer in bytes wins.
0
,1
or2
with nothing following it should outputa
,b
orc
(following the rule for3
or more). Clear (I think) from the 'edge cases', but better to spell it out. \$\endgroup\$