Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save apgordon/1a393edb296c029609a30916b314190e to your computer and use it in GitHub Desktop.
Input a paragraph and check if any of the individual words are dollar words.
letters = ("a".."z").to_a
numbers = (1..26).to_a
loop do
dollar_words = []
print "> "
input = gets.chomp.downcase
words = input.split(" ")
words.each do |word|
word_sum = 0
word.split("").delete_if{|v| v.between?("a","z") == false || v == " "}.each do |letter|
word_sum += numbers[letters.index(letter)]
end
if word_sum == 100
dollar_words.push(word)
end
end
if dollar_words.size > 0
puts dollar_words.inspect
else
puts "No dollar words."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment