Advertisement
whitestarrr

Untitled

Mar 17th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <?php
  2. $list = explode(", ", $_GET['list']);
  3. $parts = [
  4. 'CPU' => [0,85],
  5. 'ROM' => [0,45],
  6. 'RAM' => [0,35],
  7. 'VIA' => [0,45]
  8. ];
  9. $bought = [];
  10. $computers = 0;
  11. $expenses = 0;
  12. $income = 0;
  13. foreach ($list as $part) {
  14. if (!array_key_exists($part, $parts)) {
  15. continue;
  16. }
  17. $parts[$part][0]++;
  18. $bought[$part] = isset($bought[$part]) ? $bought[$part]+1 : 1;
  19. if (count($bought) == count($parts)) {
  20. foreach(array_keys($parts) as $partName) {
  21. $bought[$partName]--;
  22. if ($bought[$partName] == 0) {
  23. unset($bought[$partName]);
  24. }
  25. }
  26. $computers++;
  27. }
  28. }
  29. foreach ($parts as $part) {
  30. $modifier = $part[0] >= 5 ? 0.5 : 1;
  31. $expenses += $part[0] * $part[1] * $modifier;
  32. }
  33. $income = ($computers * 420) - $expenses;
  34. foreach ($bought as $partName => $boughtValue) {
  35. $income += ($parts[$partName][1]/2) * $boughtValue;
  36. }
  37. $partsLeft = array_sum($bought);
  38. $did = $income > 0 ? 'gained' : 'lost';
  39. echo "<ul><li>$computers computers assembled</li><li>$partsLeft parts left</li></ul><p>Nakov $did $income leva</p>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement