24
3
There are several questions regarding this game, even a king-of-the-hill contest here. But I think all those challenges and contests need a way to automatically determine the winner of a game. So:
Challenge
Given two inputs in the range ["rock", "paper", "scissors", "lizard", "spock"]
representing the selections for player 1 and player 2, determine the winner of the match.
Rules
[Winner] [action] [loser]
-----------------------------
scissors cut paper
paper covers rock
rock crushes lizard
lizard poisons spock
spock smashes scissors
scissors decapitates lizard
lizard eats paper
paper disproves spock
spock vaporizes rock
rock crushes scissors
Restrictions
- Input will be a pair of strings in the given range (no other strings can be used). You can use arrays of chars if you want, as long as they represent any of the mentioned values.
- You can choose whether to use lowercase, uppercase (
"ROCK"
) or camel case ("Rock"
) for the input strings, as long as the chosen case is the same for all inputs. - Output will be a trio of values that determine the winner, which can be anything you want as long as the answers are consistent. Example:
1
if the first input wins,2
if the second input wins,0
if there is a tie. Or maybeA
if the first input wins,B
if the second input wins,<empty string>
if there is a tie.
Goal
This is code-golf, so may the shortest program/method/function/lambda for each language win!
Tests
[Input 1] [Input 2] [Output: 1/2/0]
-----------------------------------
rock paper 2
rock scissors 1
lizard spock 1
spock rock 1
spock paper 2
rock rock 0
This comes from the sandbox.
– Charlie – 2017-11-27T09:34:21.1571Very related. – Stewie Griffin – 2017-11-27T11:43:34.380
I've closed it as a duplicate of the linked question because its just the same question with 2 new values and a slight variation on IO. – Post Rock Garf Hunter – 2017-11-27T15:34:40.603
4@WheatWizard sometimes a slight change in the input produces very different outputs. The questions may be quite similar but the two new values create more cases to consider, so the algorithms used here are different enough to make people think again (see the answers with the
cake
trick). – Charlie – 2017-11-27T15:49:53.8534I agree, and voted to reopen. – G B – 2017-11-27T16:07:13.903
@Charlie I don't feel the same way, its the same problem with a different dressing. Could I add another 2 values to make a new non-duplicate question? It would certainly change the way answers are made but I don't think it would really make it substantially different. – Post Rock Garf Hunter – 2017-11-27T16:14:07.607
"Paper disproves Spock" is my favorite. – Esolanging Fruit – 2017-11-28T02:03:50.970