Skip to content

Instantly share code, notes, and snippets.

@CyrusOfEden
Last active August 29, 2015 14:10
Show Gist options
  • Save CyrusOfEden/f5819e72569a73ec915b to your computer and use it in GitHub Desktop.
Save CyrusOfEden/f5819e72569a73ec915b to your computer and use it in GitHub Desktop.
HANDS = [:rock, :paper, :scissors, :lizard, :spock]
HANDS.freeze
RESULTS = {
rock: {
lizard: 'crushes',
scissors: 'crushes'
},
paper: {
rock: 'covers',
spock: 'disproves'
},
scissors: {
paper: 'cuts',
lizard: 'decapitate'
},
lizard: {
paper: 'eats',
spock: 'poisons'
},
spock: {
scissors: 'smashes',
vaporizes: 'rock'
}
}
RESULTS.freeze
def rpsls(first, second)
return unless validate_hand(first) && validate_hand(second)
first.to_sym!
second.to_sym!
if RESULTS[first].keys.include?(second)
winner, loser = first, second
else
winner, loser = second, first
end
"#{winner.capitalize} #{RESULTS[winner][loser]} #{loser.capitalize}"
end
def validate_hand(hand)
HANDS.include?(hand.to_sym)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment