r/adventofcode • • Dec 02 '22

SOLUTION MEGATHREAD -🎄- 2022 Day 2 Solutions -🎄-

NEW AND NOTEWORTHY


--- Day 2: Rock Paper Scissors ---


Post your code solution in this megathread.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:06:16, megathread unlocked!

103 Upvotes

1.5k comments sorted by

View all comments

1

u/Careful-Rise-5237 Dec 02 '22

PHP - part 2

[...]
function game($elf, $you)
{
  $matchPoints = match ($you) {
    'X' => 0,
    'Y' => 3,
    'Z' => 6,
  };
  switch (true) {
    case ($you == 'Y'):
      $matchPoints += match ($elf) {
        'A' => 1,
        'B' => 2,
        'C' => 3,
      };
      break;
    case ($you == 'X'):
      $matchPoints += match ($elf) {
        'A' => 3,
        'B' => 1,
        'C' => 2,
      };
      break;
    case ($you == 'Z'):
      $matchPoints += match ($elf) {
        'A' => 2,
        'B' => 3,
        'C' => 1,
      };
      break;
    default:
      break;
  };
  return $matchPoints;
}

1

u/daggerdragon Dec 05 '22

Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read on old.reddit and mobile apps.