function solve($cups, $amount) {
$graph = (new Graph(function ($graph) use ($cups, $amount) {
$capacity = $graph->values[$graph->current];
if (strlen($graph->current) == count($cups)) return [];
if ($capacity == $amount) return [];
return array_filter([
$graph->current."0" => 0,
$graph->current."1" => $cups[strlen($graph->current)]
], fn($cup) => $capacity + $cup <= $amount);
}, "highest"));
$graph->explore(function ($graph) use ($cups) {
$graph->queue->insert("0");
$graph->queue->insert("1");
$graph->values = [
"0" => 0,
"1" => $cups[0]
];
});
return $graph;
}
// ==================================================
// > SOLUTIONS
// ==================================================
$cups = $input->numbers()->sort()->reverse();
$combinations = set(solve($cups, 150)->values)->keep(150);
$solution_1 = $combinations->count();
$requirements = $combinations->keys()->map(fn ($comb) => substr_count($comb, "1"));
$solution_2 = $requirements->keep($requirements->min())->count();