Advent of code 2022/2
Ajax Direct

Answer

Part 1 :
Part 2 :
$scores = [
    "A X" => 1 + 3,
    "A Y" => 2 + 6,
    "A Z" => 3 + 0,
    "B X" => 1 + 0,
    "B Y" => 2 + 3,
    "B Z" => 3 + 6,
    "C X" => 1 + 6,
    "C Y" => 2 + 0,
    "C Z" => 3 + 3,
];

$swaps = [
    "A X" => "A Z",
    "A Y" => "A X",
    "A Z" => "A Y",
    "B X" => "B X",
    "B Y" => "B Y",
    "B Z" => "B Z",
    "C X" => "C Y",
    "C Y" => "C Z",
    "C Z" => "C X",
];

// ==================================================
// > PART 1
// ==================================================
$solution_1 = $input->lines->map(fn ($line) => $scores[$line->value])->sum();

// ==================================================
// > PART 2
// ==================================================
$solution_2 = $input->lines->map(fn ($line) => $scores[$swaps[$line->value]])->sum();