Created
December 22, 2020 21:36
-
-
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.
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
| 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