Skip to content

Instantly share code, notes, and snippets.

@alxfv
Created January 23, 2013 11:30
Show Gist options
  • Save alxfv/4604589 to your computer and use it in GitHub Desktop.
Save alxfv/4604589 to your computer and use it in GitHub Desktop.
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