Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $legendary = [
- 'fragments' => [0, 'Valanyr'],
- 'motes' => [0, 'Dragonwrath'],
- 'shards' => [0, 'Shadowmourne']
- ];
- $junk = [];
- $grind = true;
- while ($grind) {
- $items = array_map('strtolower', explode(' ', readline()));
- for ($i = 0; $i < count($items); $i += 2) {
- $quantity = intval($items[$i]);
- $material = $items[$i + 1];
- if ($material === 'fragments' || $material === 'motes' || $material === 'shards') {
- $legendary[$material][0] += $quantity;
- if ($legendary[$material][0] >= 250) {
- echo $legendary[$material][1] . " obtained!" . PHP_EOL;
- $legendary[$material][0] -= 250;
- $grind = false;
- break;
- }
- } else {
- if (!key_exists($material, $junk)) {
- $junk[$material] = 0;
- }
- $junk[$material] += $quantity;
- }
- }
- }
- uksort($legendary, function ($key1, $key2) use ($legendary) {
- if ($legendary[$key1][0] === $legendary[$key2][0]) {
- return $key1 <=> $key2;
- } else {
- return $legendary[$key2][0] <=> $legendary[$key1][0];
- }
- });
- ksort($junk);
- foreach ($legendary as $item => $quantityLeft) {
- echo $item . ': ' . $legendary[$item][0] . PHP_EOL;
- }
- foreach ($junk as $item => $quantityJunk) {
- echo $item . ': ' . $junk[$item] . PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement