Skip to content

Instantly share code, notes, and snippets.

@tbje
Created December 11, 2012 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbje/4258388 to your computer and use it in GitHub Desktop.
Save tbje/4258388 to your computer and use it in GitHub Desktop.
Phone Mnemonics
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