Created
February 5, 2014 19:51
-
-
Save Jurawa/8831653 to your computer and use it in GitHub Desktop.
Returns all the possible letter combinations for a given phone numbah.
This file contains hidden or 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
## | |
# To run: | |
# irb > require '[PATH_TO_FILE]/phone_numbah' | |
# irb > PhoneNumbah.show_possibilities [PHONE_NUMBAH] | |
## | |
class PhoneNumbah | |
Digits = { "1" => ["1"], | |
"2" => ["A", "B", "C"], | |
"3" => ["D", "E", "F"], | |
"4" => ["G", "H", "I"], | |
"5" => ["J", "K", "L"], | |
"6" => ["M", "N", "O"], | |
"7" => ["P", "Q", "R", "S"], | |
"8" => ["T", "U", "V"], | |
"9" => ["W", "X", "Y", "Z"], | |
"0" => ["0"], | |
} | |
# Takes an integer phone number of 10 digits ie. 6176100089 | |
def self.show_possibilities numbah | |
split_numbah = numbah.to_s.split '' | |
digit_letters = split_numbah.map { |digit| Digits[digit] } | |
digit_letters[0].product(*digit_letters[1..-1]).map { |combo| combo.join('') } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment