calculateScore($ownDraw, $opponentDraw); } return $score; } #[\Override] public function part2(array $data): int { $score = 0; foreach ($data as $round) { [$opponentDraw, $expectedResult] = explode(' ', $round); $opponentDraw = RPS::fromPuzzleInput($opponentDraw); $score += match ($expectedResult) { 'X' => $this->calculateScore($opponentDraw->losingOpposite(), $opponentDraw), 'Y' => $this->calculateScore($opponentDraw, $opponentDraw), 'Z' => $this->calculateScore($opponentDraw->winningOpposite(), $opponentDraw), default => 0, }; } return $score; } private function calculateScore(RPS $ownDraw, RPS $opponentDraw): int { // Win if ($ownDraw->losingOpposite() === $opponentDraw) { return $ownDraw->score() + 6; } // Lost if ($ownDraw->winningOpposite() === $opponentDraw) { return $ownDraw->score(); } // Draw. return $ownDraw->score() + 3; } }