Skip to content

Instantly share code, notes, and snippets.

@michaelfeathers
Created February 5, 2013 13:21
Show Gist options
  • Save michaelfeathers/4714410 to your computer and use it in GitHub Desktop.
Save michaelfeathers/4714410 to your computer and use it in GitHub Desktop.
ENCODER = Hash[('a'..'z').map {|x| [x,x] }].merge(Hash["aeiouya".chars.each_cons(2).to_a])
DECODER = ENCODER.invert
def encode string
string.chars.map {|c| ENCODER[c] || c }.join
end
def decode string
string.chars.map {|c| DECODER[c] || c }.join
end
def numbers_for string
string.chars.map(&:ord)
end
def text_for numbers
numbers.map(&:chr).join
end
File.open('/usr/share/dict/words').lines.each do |line|
word = line.chomp.downcase
puts "#{word}, #{encode(word)}, #{numbers_for(word)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment