Skip to content

Instantly share code, notes, and snippets.

@dividedmind
Last active December 25, 2015 13:29
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 dividedmind/6983514 to your computer and use it in GitHub Desktop.
Save dividedmind/6983514 to your computer and use it in GitHub Desktop.
#!/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