Last active
August 29, 2015 14:10
-
-
Save CyrusOfEden/f5819e72569a73ec915b to your computer and use it in GitHub Desktop.
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
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