Skip to content

Instantly share code, notes, and snippets.

@ericvanjohnson
Created March 16, 2021 03:46
Show Gist options
  • Save ericvanjohnson/f71473faa7a6fe8bd6b12bd97a966f5e to your computer and use it in GitHub Desktop.
Save ericvanjohnson/f71473faa7a6fe8bd6b12bd97a966f5e to your computer and use it in GitHub Desktop.
PHP Puzzle - php[arch] March 2021
<?php
$winner = rpsCompare('rock', 'paper');
// $winner = rpsCompare('rock', 'rock');
// $winner = rpsCompare('rock', 'scissors');
// $winner = rpsCompare('scissors', 'paper');
// $winner = rpsCompare('scissors', 'rock');
// $winner = rpsCompare('paper', 'scissors');
// $winner = rpsCompare('paper', 'rock');
if ($winner === 0) {
echo "WE HAVE A TIE!";
exit;
}
echo "Player $winner has won this round";
function rpsCompare($player_1, $player_2)
{
// We have a Tie
if ($player_1 === $player_2) {
return 0;
}
// Player 1 Wins
if ($player_1 == "rock" && $player_2 == "scissors") {
return 1;
}
if ($player_1 == "scissors" && $player_2 == "paper") {
return 1;
}
if ($player_1 == "paper" && $player_2 == "rock") {
return 1;
}
// Player 2 Wins
return 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment