SHARE
TWEET

Untitled

a guest Mar 26th, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(inputArray){
  2.     let final = inputArray.shift();
  3.     for (let i = 0; i< inputArray.length; i++) {
  4.         calculate(final,inputArray[i]);  
  5.     }
  6.  
  7.  
  8.     function calculate(finalThickness,currentThickness){
  9.         console.log(`Processing chunk ${currentThickness} microns`);
  10.         let cutsMade = 0;
  11.         let lapsMade = 0;
  12.         let grindsMade = 0;
  13.         let etchsMade = 0;
  14.         let xraysMade = 0;
  15.         let cut = currentThickness => currentThickness / 4;
  16.         let lap = currentThickness => currentThickness * 0.8;
  17.         let grind = currentThickness => currentThickness - 20;
  18.         let etch = currentThickness => currentThickness - 2
  19.         let xray = currentThickness => currentThickness + 1;
  20.    
  21.         while (((finalThickness - 1) !== currentThickness) && (finalThickness !== currentThickness)) {
  22.             if (cut(currentThickness) >= (finalThickness - 1) || cut(currentThickness) >= finalThickness) {
  23.                 currentThickness = cut(currentThickness);
  24.                 cutsMade++;
  25.             }
  26.             else if (lap(currentThickness) >= (finalThickness - 1) || lap(currentThickness) >= finalThickness) {
  27.                 currentThickness = lap(currentThickness);
  28.                 lapsMade++;
  29.             }
  30.             else if (grind(currentThickness) >= (finalThickness - 1) || grind(currentThickness) >= finalThickness) {
  31.                 currentThickness = grind(currentThickness);
  32.                 grindsMade++;
  33.             }
  34.             else if (etch(currentThickness) >= (finalThickness - 1) || etch(currentThickness) >= finalThickness) {
  35.                 currentThickness = etch(currentThickness);
  36.                 etchsMade++;
  37.    
  38.             }
  39.         }
  40.         if (finalThickness - 1 === currentThickness) {
  41.             currentThickness = xray(currentThickness);
  42.             xraysMade++;
  43.         }
  44.    
  45.         let print = (arrayMade) => {
  46.             for (let i = 0; i < arrayMade.length; i++) {
  47.                 switch (i) {
  48.                     case 0:
  49.                         if (arrayMade[i] > 0) {
  50.                             console.log(`Cut x${arrayMade[i]}`);
  51.                             console.log(`Transporting and washing`);
  52.                         }
  53.                         break;
  54.                     case 1:
  55.                         if (arrayMade[i] > 0) {
  56.                             console.log(`Lap x${arrayMade[i]}`);
  57.                             console.log(`Transporting and washing`);
  58.                         }
  59.                         break;
  60.                     case 2:
  61.                         if (arrayMade[i] > 0) {
  62.                             console.log(`Grind x${arrayMade[i]}`);
  63.                             console.log(`Transporting and washing`);
  64.                         }
  65.                         break;
  66.                     case 3:
  67.                         if (arrayMade[i] > 0) {
  68.                             console.log(`Etch x${arrayMade[i]}`);
  69.                             console.log(`Transporting and washing`);
  70.                         }
  71.                         break;
  72.                     case 4:
  73.                         if (arrayMade[i] > 0) {
  74.                             console.log(`X-ray x${arrayMade[i]}`);
  75.                         }
  76.                         break;
  77.                 }
  78.             }
  79.             console.log(`Finished crystal ${finalThickness} microns`);
  80.         };
  81.         print([cutsMade,lapsMade,grindsMade,etchsMade,xraysMade]);
  82.     }
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top