Advent of code 2023/18
Ajax Direct

Answer

Part 1 :
Part 2 :
function solve($dirs) {
    $x1 = $y1 = $x2 = $y2 = $border = $area = 0;

    foreach ($dirs as [$dir, $length]) {
        $border += $length;
        match ($dir) {
            "U" => $y2 -= $length,
            "D" => $y2 += $length,
            "L" => $x2 -= $length,
            "R" => $x2 += $length,
        };
        $area += ($y1 + $y2) * ($x1 - $x2);
        [$x1, $y1] = [$x2, $y2];
    }

    return ($area + $border) / 2 + 1;
}

$solution_1 = solve($input->lines->map(fn ($l) => explode(" ", $l)));

$solution_2 = solve($input->lines->map(fn ($line) => [
    ["R", "D", "L", "U"][substr($line, -2, 1)],
    hexdec(substr($line, -7, 5))
]));