$items = [
"weapons" => [
[8, 4, 0],
[10, 5, 0],
[25, 6, 0],
[40, 7, 0],
[74, 8, 0],
],
"armor" => [
[0, 0, 0],
[13, 0, 1],
[31, 0, 2],
[53, 0, 3],
[75, 0, 4],
[102, 0, 5],
],
"rings" => [
[0, 0, 0],
[0, 0, 0],
[25, 1, 0],
[50, 2, 0],
[100, 3, 0],
[20, 0, 1],
[40, 0, 2],
[80, 0, 3],
],
];
$solution_1 = PHP_INT_MAX;
$solution_2 = 0;
$boss_stats = $input->numbers();
foreach ($items["weapons"] as $weapon) {
foreach ($items["armor"] as $armor) {
foreach ($items["rings"] as $ring1) {
foreach ($items["rings"] as $ring2) {
if ($ring1 === $ring2) continue;
$cost = $weapon[0] + $armor[0] + $ring1[0] + $ring2[0];
$player = [
"hp" => 100,
"damage" => $weapon[1] + $armor[1] + $ring1[1] + $ring2[1],
"armor" => $weapon[2] + $armor[2] + $ring1[2] + $ring2[2]
];
$boss = [
"hp" => $boss_stats[0],
"damage" => $boss_stats[1],
"armor" => $boss_stats[2],
];
while ($player["hp"] > 0 && $boss["hp"] > 0) {
$boss["hp"] -= max(1, $player["damage"] - $boss["armor"]);
$player["hp"] -= max(1, $boss["damage"] - $player["armor"]);
}
if ($boss["hp"] <= 0) {
$solution_1 = min($solution_1, $cost);
} else {
$solution_2 = max($solution_2, $cost);
}
}
}
}
}