Advertisement
Guest User

LegendaryFarming

a guest
Mar 26th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. <?php
  2.  
  3. $keyMaterials = [];
  4. $junk = [];
  5. $win = "";
  6. $getMaterial = true;
  7. $keyMaterials['motes'] = 0;
  8. $keyMaterials['shards'] = 0;
  9. $keyMaterials['fragments'] = 0;
  10.  
  11. while ($getMaterial) {
  12.     $input = readline();
  13.     $tokens = explode(" ", $input);
  14.     $qty = 0;
  15.     $material = "";
  16.     $count = count($tokens);
  17.  
  18.     for ($i = 1; $i <= $count; $i += 2) {
  19.         $qty = intval($tokens[$i - 1]);
  20.         $material = strtolower($tokens[$i]);
  21.  
  22.         if (key_exists($material, $keyMaterials)) {
  23.             $keyMaterials[$material] += $qty;
  24.  
  25.             if ($keyMaterials[$material] >= 250 && ($material === "fragments" || $material === "shards" || $material === "motes")) {
  26.                 $win = $material;
  27.                 $keyMaterials[$material] -= 250;
  28.                 $getMaterial = false;
  29.                 break;
  30.             }
  31.         } else {
  32.             if (!key_exists($material, $junk)) {
  33.                 $junk[$material] = $qty;
  34.             } else {
  35.                 $junk[$material] += $qty;
  36.             }
  37.         }
  38.     }
  39. }
  40.  
  41. if ($win === "shards") {
  42.     echo "Shadowmourne obtained!\n";
  43. } else if ($win === "motes") {
  44.     echo "Dragonwrath obtained!\n";
  45. } else if ($win === "fragments") {
  46.     echo "Valanyr obtained!\n";
  47. }
  48.  
  49. uksort($keyMaterials, function ($mat1, $mat2) use ($keyMaterials) {
  50.     $count1 = $keyMaterials[$mat1];
  51.     $count2 = $keyMaterials[$mat2];
  52.     if ($count1 === $count2) {
  53.         $name1 = $mat1;
  54.         $name2 = $mat2;
  55.         return $name1 <=> $name2;
  56.     }
  57.     return $count2 <=> $count1;
  58. });
  59.  
  60. uksort($junk, function ($junk1, $junk2) use ($junk) {
  61.     $name1 = $junk1;
  62.     $name2 = $junk2;
  63.     return $name1 <=> $name2;
  64. });
  65.  
  66. foreach ($keyMaterials as $key => $value) {
  67.     echo "$key" . ": " . $value . PHP_EOL;
  68. }
  69.  
  70. foreach ($junk as $key => $value) {
  71.     echo "$key" . ": " . $value . PHP_EOL;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement