Skip to content

Instantly share code, notes, and snippets.

@mrdougwright
Last active August 29, 2015 14:10
Show Gist options
  • Save mrdougwright/3b95c798646403f061f2 to your computer and use it in GitHub Desktop.
Save mrdougwright/3b95c798646403f061f2 to your computer and use it in GitHub Desktop.
Life Counter for Words
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