Skip to content

Instantly share code, notes, and snippets.

@omarqureshi
Created February 18, 2013 13:09
Show Gist options
  • Save omarqureshi/4977247 to your computer and use it in GitHub Desktop.
Save omarqureshi/4977247 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
MAP = {"a" => "2", "b" => "22", "c" => "222", "d" => "3", "e" => "33", "f" => "333", "g" => "4", "h" => "44", "i" => "444", "j" => "5", "k" => "55", "l" => "555", "m" => "6", "n" => "66", "o" => "666", "p" => "7", "q" => "77", "r" => "777", "s" => "7777", "t" => "8", "u" => "88", "v" => "888", "w" => "9", "x" => "99", "y" => "999", "z" => "9999", " " => "0"}
lines = $<.readlines
lines.shift
while lines.any?
message = lines.shift.chomp.split(//).map {|x| MAP[x]}
# ["44", "444"]
output = ""
for letter in message
# "44"
output += " " if letter[0] == output[-1]
output += letter
end
puts output
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment