// ==================================================
// > PART 1
// ==================================================
$grid = [];
foreach ($input->lines as $claim) {
[$id, $x, $y, $w, $h] = $claim->numbers();
for ($dx = 0; $dx < $w; $dx++) {
for ($dy = 0; $dy < $h; $dy++) {
$grid[($x + $dx).";".($y + $dy)] ??= 0;
$grid[($x + $dx).";".($y + $dy)]++;
}
}
}
$solution_1 = count(array_filter($grid, fn ($n) => $n > 1));
// ==================================================
// > PART 2
// ==================================================
foreach ($input->lines as $claim) {
[$id, $x, $y, $w, $h] = $claim->numbers();
$overlaped = false;
for ($dx = 0; $dx < $w; $dx++) {
for ($dy = 0; $dy < $h; $dy++) {
if ($grid[($x + $dx).";".($y + $dy)] > 1) {
$overlaped = true;
break 2;
}
}
}
if (!$overlaped) break;
}
$solution_2 = $id;