$ticket = [
"children" => 3,
"cats" => 7, // >
"samoyeds" => 2,
"pomeranians" => 3, // <
"akitas" => 0,
"vizslas" => 0,
"goldfish" => 5, // <
"trees" => 3, // >
"cars" => 2,
"perfumes" => 1,
];
$sues = $input->lines->map(function ($sue) {
preg_match_all("/ ([a-z]+): (\d+)/", $sue, $matches);
return array_combine($matches[1], $matches[2]);
});
// ==================================================
// > PART 1
// ==================================================
foreach ($sues as $i=>$sue) {
foreach ($sue as $item=>$count) {
if ($ticket[$item] != $count) {
continue 2;
}
}
break;
}
$solution_1 = $i + 1;
// ==================================================
// > PART 2
// ==================================================
foreach ($sues as $i=>$sue) {
foreach ($sue as $item=>$count) {
switch ($item) {
case "cats": case "trees":
if ($count <= $ticket[$item]) continue 3;
break;
case "pomeranians": case "goldfish":
if ($count >= $ticket[$item]) continue 3;
break;
default:
if ($ticket[$item] != $count) continue 3;
break;
}
}
break;
}
$solution_2 = $i + 1;