// ==================================================
// > PART 1
// ==================================================
$r_2 = 0;
$r_3 = 0;
foreach ($input->lines as $line) {
$repeats = $line->chars->occurrences();
$r_2 += $repeats->search(2) ? 1 : 0;
$r_3 += $repeats->search(3) ? 1 : 0;
}
$solution_1 = $r_2 * $r_3;
// ==================================================
// > PART 2
// ==================================================
foreach ($input->lines as $i => $line) {
$chars1 = $line->chars->mapAssoc(fn ($i, $char) => [$i => "$char$i"]);
for ($j = $i + 1; $j < $input->lines->count(); $j++) {
$chars2 = $input->lines[$j]->chars->mapAssoc(fn ($i, $char) => [$i => "$char$i"]);;
if ($chars1->remove($chars2)->count() == 1) {
break 2;
}
}
}
$solution_2 = $chars1->keep($chars2)->map(fn ($char) => $char[0])->join();