Created
January 23, 2013 11:30
-
-
Save alxfv/4604589 to your computer and use it in GitHub Desktop.
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
def rps_game_winner(game) | |
raise WrongNumberOfPlayersError unless game.length == 2 | |
2.times do |i| | |
raise NoSuchStrategyError unless ['P', 'S', 'R'].include? game[i][1].upcase | |
end | |
first = game[0][1].upcase | |
second = game[1][1].upcase | |
if first == 'P' | |
second == 'S' ? game[1] : game[0] | |
elsif first == 'S' | |
second == 'R' ? game[1] : game[0] | |
else | |
second == 'P' ? game[1] : game[0] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment