Last active
December 25, 2015 13:29
-
-
Save dividedmind/6983514 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# I opted for a more conventional mapping, as in | |
# https://en.wikipedia.org/wiki/File:Telephone-keypad2.svg | |
MAP = { | |
'2' => 'abc', | |
'3' => 'def', | |
'4' => 'ghi', | |
'5' => 'jkl', | |
'6' => 'mno', | |
'7' => 'pqrs', | |
'8' => 'tuv', | |
'9' => 'wxyz' | |
} | |
number = gets.strip | |
raise "wrong format" unless number =~ /\d{9}/ | |
lists = number.chars.map {|c| (MAP[c] || c).chars} | |
puts lists.shift.product(*lists).map(&:join) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment