DARIMI27

Radio Crystals

Aug 26th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.26 KB | None | 0 0
  1. <?php
  2. $input = array_map("doubleval", explode(", ", readline()));
  3. //$input = array_map("doubleval", explode(", ", "25, 24"));
  4. $finalResult = $input[0];
  5. $startWeigth = $input[1];
  6. $count = 0;
  7. if ($startWeigth+1<$finalResult){
  8.     exit;
  9. }
  10. echo "Processing chunk $startWeigth microns" . PHP_EOL;
  11. while ($startWeigth / 4 >= $finalResult) {
  12.     $count++;
  13.     $startWeigth = Cut($startWeigth);
  14.  
  15. }
  16. if($count!=0) {
  17.     echo "Cut x$count" . PHP_EOL;
  18.     Check($startWeigth,$finalResult);
  19.     $startWeigth=TransportingAndWashing($startWeigth);
  20. }
  21. Check($startWeigth,$finalResult);
  22. $count = 0;
  23. while ($startWeigth - (20 * $startWeigth) / 100 >= $finalResult) {
  24.     $count++;
  25.     $startWeigth = Lap($startWeigth);
  26. }
  27. if($count!=0) {
  28.     echo "Lap x$count" . PHP_EOL;
  29.     Check($startWeigth,$finalResult);
  30.     $startWeigth=TransportingAndWashing($startWeigth);
  31. }
  32. $count = 0;
  33. Check($startWeigth,$finalResult);
  34. while ($startWeigth - 20 >= $finalResult) {
  35.     $count++;
  36.     $startWeigth = Grind($startWeigth);
  37. }
  38. if($count!=0) {
  39.     echo "Grind x$count" . PHP_EOL;
  40.     Check($startWeigth,$finalResult);
  41.     $startWeigth=TransportingAndWashing($startWeigth);
  42. }
  43. $count = 0;
  44. Check($startWeigth,$finalResult);
  45. while ($startWeigth - 2 >= $finalResult - 1) {
  46.     $count++;
  47.     $startWeigth = Etch($startWeigth);
  48. }
  49. if($count!=0) {
  50.     echo "Etch x$count" . PHP_EOL;
  51.     Check($startWeigth,$finalResult);
  52.     $startWeigth=TransportingAndWashing($startWeigth);
  53. }
  54. Check($startWeigth,$finalResult);
  55. if ($startWeigth == $finalResult) {
  56.     exit;
  57. } else {
  58.     $startWeigth= Xray($startWeigth);
  59.     echo "X-ray x1" . PHP_EOL;
  60.     Check($startWeigth,$finalResult);
  61.     echo "Finished crystal $startWeigth microns";
  62. }
  63.  
  64. function Check($a,$b){
  65.     if ($a == $b) {
  66.         echo "Finished crystal $a microns".PHP_EOL;
  67.         exit;
  68.     }
  69.  
  70. }
  71. function TransportingAndWashing($a)
  72. {
  73.     $b=floor($a);
  74.     echo "Transporting and washing" . PHP_EOL;
  75.     return $b;
  76. }
  77.  
  78. function Cut($a)
  79. {
  80.     $a = $a / 4;
  81.     return $a;
  82. }
  83.  
  84. function Lap($a)
  85. {
  86.     $b = $a - (20 * $a) / 100;
  87.     return $b;
  88. }
  89.  
  90. function Grind($a)
  91. {
  92.     $a = $a - 20;
  93.     return $a;
  94. }
  95.  
  96. function Etch($a)
  97. {
  98.     $a = $a - 2;
  99.     return $a;
  100. }
  101.  
  102. function Xray($a)
  103. {
  104.     $a = $a + 1;
  105.     return $a;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment