Skip to content

Instantly share code, notes, and snippets.

@apgordon
Last active December 22, 2020 21:36
Show Gist options
  • Select an option

  • Save apgordon/af8befadb6473994324bcfe2c8ed8b5a to your computer and use it in GitHub Desktop.

Select an option

Save apgordon/af8befadb6473994324bcfe2c8ed8b5a to your computer and use it in GitHub Desktop.
Input a word and check its dollar word sum
letters = ("a".."z").to_a
numbers = (1..26).to_a
loop do
print "> "
input = gets.chomp.downcase
word_sum = 0
input.split("").delete_if{|v| v.between?("a","z") == false || v == " "}.each do |letter|
word_sum += numbers[letters.index(letter)]
end
puts "#{word_sum}\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment