-
-
Save anonymous/d6037a4b4b7e278d7ff5 to your computer and use it in GitHub Desktop.
Is there any redundancy in this script?
This file contains 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
#!/usr/bin/env ruby | |
system("clear") | |
require 'set' | |
feelings = { | |
euphoria: Set.new(%w[happy high cool]), | |
loller: Set.new(%w[happy arst neio]), | |
dysphoria: Set.new(%w[sad tired low]), | |
miserable: Set.new(%w[sad angry gay]) | |
} | |
puts "What are you feeling right now?" | |
input = Set.new gets.scan(/\w+/) | |
name, _ = feelings.find{ |_,matches| matches.subset?(input)} | |
feelings.each do |disease,criteria| | |
leftovers = criteria - input | |
if leftovers.empty? | |
puts "Complete match found ---#{name}---" | |
elsif input.intersect? criteria | |
percent_match = ((criteria.size - leftovers.size.to_f) / criteria.size) | |
* 100 | |
puts "Incomplete match ---#{disease}--- %#{percent_match.round(2)}" | |
elsif input.disjoint? criteria | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment