Skip to content

Instantly share code, notes, and snippets.

Created October 6, 2011 10:10
Show Gist options
  • Save anonymous/1267043 to your computer and use it in GitHub Desktop.
Save anonymous/1267043 to your computer and use it in GitHub Desktop.
File.open("words.txt") do |f|
f.each do|word|
word=word.to_s.chomp.downcase
p word
word.each_char do |l| #extrating letters
puts "\t Current letter: #{l}"
puts case l
when ('a'||'b'||'c') then 2
when ('d'||'e'||'f') then 3
when ('g'||'h'||'i') then 4
when ('j'||'k'||'l') then 5
when ('m'||'n'||'o') then 6
when ('p'||'q'||'r'||'s') then 7
when ('t'||'u'||'v') then 8
else 9
end
end
end
end
=begin
word.txt contains text like:
---Start of word.txt---
Cappuccino
Chocolate
Cinnamon
Coffee
Latte
Vanilla
---End of word.txt---
All what I'm doing is extracting each word and displaying telephonic numerical for each letter of corresponding word.
It is giving wrong equivalents. Dunno why.
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment