$items = [
"weapons" => [
[8, 4, 0], // Dagger
[10, 5, 0], // Shortsword
[25, 6, 0], // Warhammer
[40, 7, 0], // Longsword
[74, 8, 0], // Greataxe
],
"armor" => [
[0, 0, 0], // None
[13, 0, 1], // Leather
[31, 0, 2], // Chainmail
[53, 0, 3], // Splintmail
[75, 0, 4], // Bandedmail
[102, 0, 5], // Platemail
],
"rings" => [
[0, 0, 0], // None 1
[0, 0, 0], // None 2
[25, 1, 0], // Damage +1
[50, 2, 0], // Damage +2
[100, 3, 0], // Damage +3
[20, 0, 1], // Defense +1
[40, 0, 2], // Defense +2
[80, 0, 3], // Defense +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);
}
}
}
}
}