Petar_Dzhidzhev

Untitled

Oct 23rd, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unction solve(arr) {
  2.     let targetThick = +arr[0];
  3.     let cutCounter = 0;
  4.     let lapCounter = 0;
  5.     let grindCounter = 0;
  6.     let etchCounter = 0;
  7.  
  8.     for (let i = 1; i < arr.length; i++) {
  9.         let chunk = +arr[i];
  10.  
  11.         console.log(`Processing chunk ${chunk} microns`);
  12.         if (chunk >= targetThick * 4) {
  13.             chunk = cutting(chunk);
  14.             chunk = transportAndWash(chunk);
  15.             console.log(`Cut x${cutCounter}`);
  16.             console.log('Transporting and washing');
  17.  
  18.             if (targetThick === chunk) {
  19.                 console.log(`Finished crystal ${targetThick} microns`);
  20.             }
  21.         }
  22.         if (chunk > targetThick * 1.20) {
  23.             chunk = lap(chunk);
  24.             chunk = transportAndWash(chunk);
  25.             console.log(`Lap x${lapCounter}`);
  26.             console.log('Transporting and washing');
  27.  
  28.             if (targetThick === chunk) {
  29.                 console.log(`Finished crystal ${targetThick} microns`);
  30.             }
  31.         }
  32.         if (chunk > targetThick + 20) {
  33.             chunk = grind(chunk);
  34.             chunk = transportAndWash(chunk);
  35.             console.log(`Grind x${grindCounter}`);
  36.             console.log('Transporting and washing');
  37.  
  38.             if (targetThick === chunk) {
  39.                 console.log(`Finished crystal ${targetThick} microns`);
  40.             }
  41.         }
  42.         if (chunk >= targetThick + 1) {
  43.             chunk = etch(chunk);
  44.             chunk = transportAndWash(chunk);
  45.             console.log(`Etch x${etchCounter}`);
  46.             console.log('Transporting and washing');
  47.  
  48.             if (targetThick === chunk) {
  49.                 console.log(`Finished crystal ${targetThick} microns`);
  50.             }
  51.         }
  52.         if (targetThick > chunk) {
  53.             chunk = xRay(chunk);
  54.             console.log('X-ray x1');
  55.  
  56.             if (targetThick === chunk) {
  57.                 console.log(`Finished crystal ${targetThick} microns`);
  58.             }
  59.         }
  60.         cutCounter = 0;
  61.         etchCounter = 0;
  62.         lapCounter = 0;
  63.         grindCounter = 0;
  64.     }
  65.  
  66.     function cutting(chunk) {
  67.  
  68.         while (chunk >= targetThick * 4) {
  69.             chunk /= 4;
  70.             cutCounter++;
  71.         }
  72.         return chunk;
  73.     }
  74.  
  75.     function lap(chunk) {
  76.         while (chunk >= targetThick * 1.20) {
  77.             chunk *= 0.8;
  78.             lapCounter++;
  79.         }
  80.         return chunk;
  81.     }
  82.  
  83.     function grind(chunk) {
  84.         while (chunk >= targetThick + 20) {
  85.             chunk -= 20;
  86.             grindCounter++;
  87.         }
  88.         return chunk;
  89.     }
  90.  
  91.     function etch(chunk) {
  92.         while (chunk >= targetThick + 1) {
  93.             chunk -= 2;
  94.             etchCounter++;
  95.         }
  96.         return chunk;
  97.     }
  98.  
  99.     function xRay(chunk) {
  100.         return chunk + 1;
  101.     }
  102.  
  103.     function transportAndWash(chunk) {
  104.  
  105.         chunk = Math.trunc(chunk);
  106.         return chunk;
  107.     }
  108. }
Add Comment
Please, Sign In to add comment