Advertisement
vladovip

Radio Crystals

Feb 7th, 2021
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function radioCrystal(input){
  2.     var target = Number(input[0]);
  3.  
  4.     function process(crystalThickness, action){
  5.         switch(action) {
  6.             case "cut":
  7.                 crystalThickness = crystalThickness >> 2;
  8.                 cutCount++;
  9.                 break;
  10.             case "lap":
  11.                 crystalThickness /= 1.25;
  12.                 lapCount++;
  13.                 break;
  14.             case "grind":
  15.                 crystalThickness -= 20;
  16.                 grindCount++;
  17.                 break;
  18.             case "etch":
  19.                 crystalThickness -= 2;
  20.                 etchCount++;
  21.                 break;
  22.             case "xRay":
  23.                 crystalThickness += 1;
  24.                 xrayCount++;
  25.                 return crystalThickness;
  26.         }
  27.  
  28.         return transportingWashing(crystalThickness);
  29.     }
  30.  
  31.     function transportingWashing(crystalThickness) {
  32.         return Math.floor(crystalThickness);
  33.     }
  34.  
  35.     for(let i = 1; i < input.length; i++){
  36.         var current = input[i];
  37.         var cutCount = 0, lapCount = 0, grindCount = 0, etchCount = 0, xrayCount = 0;
  38.         var used = false;
  39.  
  40.         console.log(`Processing chunk ${current} microns`);
  41.  
  42.         while(current != target){
  43.             while(current >> 2 >= target - 1){
  44.                 current = process(current,"cut");
  45.             }
  46.             while(current / 1.25 >= target - 1){
  47.                 current = process(current,"lap");
  48.             }
  49.             while(current - 20 >= target - 1){
  50.                 current = process(current,"grind");
  51.             }
  52.             while(current - 2 >= target - 1){
  53.                 current = process(current,"etch");
  54.             }
  55.             if(current + 1 == target && used == false){
  56.                 used = true;
  57.                 current = process(current,"xRay");
  58.             }
  59.         }
  60.  
  61.         if(cutCount > 0) {
  62.             console.log(`Cut x${cutCount}`)
  63.             console.log("Transporting and washing");
  64.         }
  65.  
  66.         if(lapCount > 0) {
  67.             console.log(`Lap x${lapCount}`)
  68.             console.log("Transporting and washing");
  69.         }
  70.  
  71.         if(grindCount > 0) {
  72.             console.log(`Grind x${grindCount}`)
  73.             console.log("Transporting and washing");
  74.         }
  75.  
  76.         if(etchCount > 0) {
  77.             console.log(`Etch x${etchCount}`)
  78.             console.log("Transporting and washing");
  79.         }
  80.  
  81.         if(used) {
  82.             console.log(`X-ray x1`)
  83.         }
  84.  
  85.         console.log(`Finished crystal ${target} microns`)
  86.     }
  87. }
  88. radioCrystal([1375, 50000]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement