Created
February 14, 2011 00:12
-
-
Save jimfisher/825328 to your computer and use it in GitHub Desktop.
Coded by Jim Fisher github: @jimfisher twitter: @jimfish #A simple app for converting words into NUMERIC representations and then making that into a % # Based on a silly email I received found below ###### EMAIL ######
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
begin | |
# lets define numbers for every letter as A = 1, B = 2, C=3, etc. | |
alphabet_numbers = {} | |
('a'..'z').each_with_index{|x,y| alphabet_numbers[x] = y+1} | |
# lets get a word | |
loop do | |
puts "Please enter a word to convert to a percent (ctrl C to exit):" | |
input = gets.chomp.downcase | |
# lets process the word | |
sum = input.split("").map{|l|alphabet_numbers[l].to_i}.reduce(&:+) | |
# lets print the result | |
puts sum.to_s + "%" | |
end | |
rescue Interrupt | |
puts "\n Have a nice day" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment