Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = array_map("doubleval", explode(", ", readline()));
- //$input = array_map("doubleval", explode(", ", "25, 24"));
- $finalResult = $input[0];
- $startWeigth = $input[1];
- $count = 0;
- if ($startWeigth+1<$finalResult){
- exit;
- }
- echo "Processing chunk $startWeigth microns" . PHP_EOL;
- while ($startWeigth / 4 >= $finalResult) {
- $count++;
- $startWeigth = Cut($startWeigth);
- }
- if($count!=0) {
- echo "Cut x$count" . PHP_EOL;
- Check($startWeigth,$finalResult);
- $startWeigth=TransportingAndWashing($startWeigth);
- }
- Check($startWeigth,$finalResult);
- $count = 0;
- while ($startWeigth - (20 * $startWeigth) / 100 >= $finalResult) {
- $count++;
- $startWeigth = Lap($startWeigth);
- }
- if($count!=0) {
- echo "Lap x$count" . PHP_EOL;
- Check($startWeigth,$finalResult);
- $startWeigth=TransportingAndWashing($startWeigth);
- }
- $count = 0;
- Check($startWeigth,$finalResult);
- while ($startWeigth - 20 >= $finalResult) {
- $count++;
- $startWeigth = Grind($startWeigth);
- }
- if($count!=0) {
- echo "Grind x$count" . PHP_EOL;
- Check($startWeigth,$finalResult);
- $startWeigth=TransportingAndWashing($startWeigth);
- }
- $count = 0;
- Check($startWeigth,$finalResult);
- while ($startWeigth - 2 >= $finalResult - 1) {
- $count++;
- $startWeigth = Etch($startWeigth);
- }
- if($count!=0) {
- echo "Etch x$count" . PHP_EOL;
- Check($startWeigth,$finalResult);
- $startWeigth=TransportingAndWashing($startWeigth);
- }
- Check($startWeigth,$finalResult);
- if ($startWeigth == $finalResult) {
- exit;
- } else {
- $startWeigth= Xray($startWeigth);
- echo "X-ray x1" . PHP_EOL;
- Check($startWeigth,$finalResult);
- echo "Finished crystal $startWeigth microns";
- }
- function Check($a,$b){
- if ($a == $b) {
- echo "Finished crystal $a microns".PHP_EOL;
- exit;
- }
- }
- function TransportingAndWashing($a)
- {
- $b=floor($a);
- echo "Transporting and washing" . PHP_EOL;
- return $b;
- }
- function Cut($a)
- {
- $a = $a / 4;
- return $a;
- }
- function Lap($a)
- {
- $b = $a - (20 * $a) / 100;
- return $b;
- }
- function Grind($a)
- {
- $a = $a - 20;
- return $a;
- }
- function Etch($a)
- {
- $a = $a - 2;
- return $a;
- }
- function Xray($a)
- {
- $a = $a + 1;
- return $a;
- }
Advertisement
Add Comment
Please, Sign In to add comment