Advent of code 2019/16
Ajax Direct

Answer

Part 1 :
Part 2 :
// ==================================================
// > PART 1
// ==================================================
$digit = (array) $input->chars();
$pattern = [0, 1, 0, -1];
$patterns = [];
for ($y = 0; $y < count($digit) * 2; $y++) {
    for ($x = 0; $x <= count($digit) * 2; $x++) {
        $pos = (ceil(($x + 2) / ($y + 1) - 1) % count($pattern));
        $patterns[$y][$x] = $pattern[$pos];
    }
}

for ($i = 0; $i < 100; $i++) {
    $output = [];
    for ($y = 0; $y < count($digit); $y++) {
        $output[$y] = [];
        for ($x = 0; $x < count($digit); $x++) {
            $output[$y][$x] = $patterns[$y][$x] * (int) $digit[$x];
        }
    }
    $digit = array_map(fn ($d) => abs(array_sum($d) % 10), $output);
}

$solution_1 = implode("", array_slice($digit, 0, 8));

// ==================================================
// > PART 2
// ==================================================
$data = $input->chars()->repeat(10000)->slice(int($input->sub(0, 7)));

for ($i = 0; $i < 100; $i++) {
    $sum = 0;
    for ($j = $data->count() - 1; $j >= 0; $j--) {
        $sum += $data[$j];
        $data[$j] = $sum % 10;
    }
}

$solution_2 = $data->slice(0, 8)->join("");