Advertisement
YanislavD

Crystals

Mar 10th, 2025 (edited)
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (input) {
  2.     let needMicrons = input[0];
  3.     let cut = 0;
  4.     let lap = 0;
  5.     let grind = 0;
  6.     let etch = 0;
  7.     let xray = 0;
  8.  
  9.     for (let i = 0; i < input.length - 1; i++) {
  10.         let curentCrystal = input[i+1];
  11.  
  12.         while (curentCrystal > needMicrons) {
  13.  
  14.             if (curentCrystal / 4 >= needMicrons) {
  15.                 curentCrystal /= 4;
  16.                 cut++;
  17.             } else if (curentCrystal - (curentCrystal * 0.20) >= needMicrons) {
  18.  
  19.                 if (lap == 0) {
  20.                     curentCrystal = Math.floor(curentCrystal);
  21.                 }
  22.  
  23.                 curentCrystal -= curentCrystal * 0.20;
  24.                 lap++;
  25.  
  26.             } else if (curentCrystal - 20 >= needMicrons) {
  27.  
  28.                 if (grind == 0) {
  29.                     curentCrystal = Math.floor(curentCrystal);
  30.                 }
  31.  
  32.                 curentCrystal -= 20;
  33.                 grind++;
  34.  
  35.             } else if (curentCrystal - 2 >= needMicrons) {
  36.  
  37.                 if (etch == 0) {
  38.                     curentCrystal = Math.floor(curentCrystal);
  39.                 }
  40.  
  41.                 curentCrystal -= 2;
  42.                 etch++;
  43.             } else if (xray == 0){
  44.  
  45.                 curentCrystal = Math.floor(curentCrystal);
  46.                 curentCrystal++;
  47.                 xray++;
  48.             }
  49.         }
  50.  
  51.         console.log(`Processing chunk ${input[i+1]} microns`)
  52.  
  53.         if (cut > 0) {
  54.              console.log(`Cut x${cut}`);
  55.              console.log(`Transporting and washing`);
  56.              cut = 0;
  57.         }
  58.  
  59.         if (lap > 0) {
  60.              console.log(`Lap x${lap}`);
  61.              console.log(`Transporting and washing`);
  62.              lap = 0;
  63.         }
  64.  
  65.         if (grind > 0) {
  66.              console.log(`Grind x${grind}`);
  67.              console.log(`Transporting and washing`);
  68.              grind = 0;
  69.         }
  70.  
  71.         if (etch > 0) {
  72.              console.log(`Etch x${etch}`);
  73.              console.log(`Transporting and washing`);
  74.              etch = 0;
  75.         }
  76.  
  77.         if (xray > 0) {
  78.              console.log(`X-ray x${xray}`);
  79.              xray = 0;
  80.         }
  81.  
  82.         console.log(`Finished crystal ${needMicrons} microns`)
  83.     }
  84. }
  85.  
  86. solve([1000, 4000, 8100]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement