Created
December 11, 2012 13:00
-
-
Save tbje/4258388 to your computer and use it in GitHub Desktop.
Phone Mnemonics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package misc | |
class PhoneMnemonics(words: Set[String]) { | |
val codeToChars: Map[Char, String] = | |
Map( | |
'2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL", | |
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ" | |
) | |
/** | |
* Inverse of codeToChars, | |
* e.g. 'A' -> '2', 'B' -> '2'. | |
*/ | |
val charCode: Map[Char, Char] = | |
Map.empty | |
/** | |
* Map a word to its digit representation, | |
* e.g. "Java" -> "5282". | |
*/ | |
def wordCode(word: String): String = | |
"" | |
/** | |
* Group all words by their number representations, | |
* e.g. "5282" -> Set("Java", "Kata", ...). | |
*/ | |
val wordsByNumber: Map[String, Set[String]] = | |
Map.empty | |
/** | |
* All ways to encode a number as a phrase, i.e. as a sequence of words. | |
*/ | |
def encode(number: String): Set[Seq[String]] = | |
Set.empty | |
/** | |
* Maps a number to the set of all phrases that can represent it. | |
*/ | |
def translate(number: String): Set[String] = | |
encode(number) map (_ mkString " ") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment