Advent of code 2019/3
Ajax Direct

Answer

Part 1 :
Part 2 :
$directions = $input->lines->map(fn($line) => $line->split(",")->map(fn ($direction) => [direction($direction[0]), (int) substr($direction, 1)]));

$wires = set([0, 1])->map(function($i) use ($directions) {
    return xy()->directions($directions[$i], true)->getFullHistory()->slice(1)->map(
        fn ($xy) => $xy[0] . ";" . $xy[1]
    );
});

// ==================================================
// > SOLUTION 1
// ==================================================
$solution_1 = $wires[0]->keep($wires[1])->map(function($xy) {
    $xy = explode(";", $xy);
    return abs($xy[0]) + abs($xy[1]);
})->sort()->first();

// ==================================================
// > SOLUTION 2
// ==================================================
$steps = [$wires[0]->keep($wires[1]), $wires[1]->keep($wires[0])];

$solution_2 = $steps[0]->map(
    (fn ($intersection, $count) => $count + $steps[1]->search($intersection))
, true)->sort()->first() + 4;