Skip to content

Instantly share code, notes, and snippets.

/feel.rb Secret

Created March 19, 2016 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d6037a4b4b7e278d7ff5 to your computer and use it in GitHub Desktop.
Save anonymous/d6037a4b4b7e278d7ff5 to your computer and use it in GitHub Desktop.
Is there any redundancy in this script?
#!/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