Last active
August 29, 2015 14:10
-
-
Save mrdougwright/3b95c798646403f061f2 to your computer and use it in GitHub Desktop.
Life Counter for Words
This file contains hidden or 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
ALPHA = %W(0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) | |
def read_word(word) | |
word.gsub(/\s+/, '').upcase.split('').map{|l| ALPHA.index(l)}.reduce(:+) | |
end | |
def get_word | |
puts "Enter a word or more for life count.\n(type quit to quit):" | |
word = gets.chomp | |
p read_word(word) | |
return if word == "quit" | |
get_word | |
end | |
get_word |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment