Phone to letter translation
Phone keypads and rotary dials have little letters on them. Most numbers translate into letters. Of course, with only 10 digits, but 26 letters, there is a problem: the translation from letters to numbers is lossy. When translating from numbers to letters, there is always more than one possible interpretation.
Write a function that takes a string of digits and returns a collection of the possible strings of letters it corresponds to.
Examples
(digits->letters "22") ;=> ["aa" "ab" "ac" "ba" "bb" "bc" "ca" "cb" "cc"]
Here are the mappings you should use:
1: no letters
2: abc
3: def
4: ghi
5: jkl
6: mno
7: pqrs
8: tuv
9: wxyz
0: space
If a character appears in the input that does not have a mapping, it will appear in the output untranslated.
Thanks to this site for the problem idea, where it is rated Expert in JavaScript. The problem has been modified.
Please submit your solutions as comments on this gist.
To subscribe: https://purelyfunctional.tv/newsletter/
I'm relatively new to Clojure, so it's quite likely I'm missing something obvious.
I thought I had a solution, until I realized clojure.core/for was a macro. So then I thought I had I bad solution, to make a macro that allows me to have a "variadic for" (not really the best name, just couldn't think of a better one for now). I think I might be close, but maybe it's not actually possible like this. I know you wouldn't actually want to use a macro for this problem as there are other ways of achieving the same result, but I am curious how and if it can be done for the sake of learning.