Created
September 20, 2010 00:22
-
-
Save benui-dev/587258 to your computer and use it in GitHub Desktop.
This file contains 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
require 'pp' | |
input = <<eos | |
Hello there | |
eos | |
# Randomise order of a-z | |
rand_characters = ('a'..'z').sort_by { rand } | |
encoding = Hash.new | |
rand_characters.each_with_index do |letter, index| | |
encoding[letter] = index + 1 # Let's make it 1..26 | |
end | |
output = Array.new | |
# Arrays of arrays | |
input.downcase.split(/\s/).each do |word| | |
# Swap from letters to numbers | |
word_arr = word.split('').collect do |letter| | |
encoding[letter] | |
end | |
output.push( word_arr ) | |
end | |
pp output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment