Advent of code 2020/2
Ajax Direct

Answer 10ms

Part 1 : 548 Part 2 : 502
// ==================================================
// > PART 1
// ==================================================
$solution_1 = $input->lines->reduce(function ($total, $line) {
    preg_match('/^(\d+)-(\d+) (\w): (\w+)$/', $line, $matches);
    [$min, $max, $letter, $password] = array_slice($matches, 1);
    return $total + in_array(substr_count($password, $letter), range($min, $max));
}, 0);

// ==================================================
// > PART 2
// ==================================================
$solution_2 = $input->lines->reduce(function ($total, $line) {
    preg_match('/^(\d+)-(\d+) (\w): (\w+)$/', $line, $matches);
    [$min, $max, $letter, $password] = array_slice($matches, 1);
    return $total + (($password[$min - 1] == $letter) ^ ($password[$max - 1] == $letter));
}, 0);