Advertisement
dimoBs

Radio Crystals

Feb 6th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. function solve(arr) {
  2.  
  3. for (let i = 1; i < arr.length; i++) {
  4.  
  5. let inputShape = [];
  6. inputShape = arr[i];
  7. let bestShape = arr[0];
  8. let currentOpr = 0;
  9. let cut = x => x / 4;
  10. let counterCut = 0;
  11. let lap = x => x - x * 0.20;
  12. let counterLaps = 0;
  13. let grind = x => x - 20;
  14. let counterGrind = 0;
  15. let etch = x => x - 2;
  16. let counterEtch = 0;
  17. let xRay = x => x + 1; //only ONCE
  18. let flag = false;
  19.  
  20. console.log(`Processing chunk ${arr[i]} microns`);
  21.  
  22. cuts(currentOpr);
  23. if (flag) {
  24. currentOpr = Math.floor(currentOpr);
  25. console.log(`Cut x${counterCut}`);
  26. console.log(`Transporting and washing`);
  27. flag = false;
  28. }
  29. laps(currentOpr);
  30. if (flag) {
  31. currentOpr = Math.floor(currentOpr);
  32. console.log(`Lap x${counterLaps}`);
  33. console.log(`Transporting and washing`);
  34. flag = false;
  35. }
  36. grinds(currentOpr);
  37. if (flag) {
  38. currentOpr = Math.floor(currentOpr);
  39. console.log(`Grind x${counterGrind}`);
  40. console.log(`Transporting and washing`);
  41. flag = false;
  42. }
  43. etchs(currentOpr);
  44. if (flag) {
  45. currentOpr = Math.floor(currentOpr);
  46. console.log(`Etch x${counterEtch}`);
  47. console.log(`Transporting and washing`);
  48. flag = false;
  49. }
  50. if ((inputShape + 1) === bestShape) {
  51. xRayOnlyOnce(currentOpr);
  52. }
  53. console.log(`Finished crystal ${currentOpr} microns`);
  54.  
  55. function cuts(n) {
  56. currentOpr = inputShape;
  57. while (inputShape >= bestShape) {
  58.  
  59. inputShape = cut(inputShape)
  60. if (inputShape >= bestShape) {
  61. currentOpr = inputShape;
  62. counterCut++;
  63. flag = true;
  64. }
  65. }
  66.  
  67. return currentOpr;
  68. }
  69. function laps(n) {
  70.  
  71. inputShape = currentOpr;
  72. while (inputShape > bestShape) {
  73.  
  74. inputShape = lap(inputShape)
  75. if (inputShape > bestShape) {
  76. currentOpr = inputShape;
  77. counterLaps++;
  78. flag = true;
  79. }
  80.  
  81. }
  82.  
  83. return currentOpr;
  84.  
  85. }
  86. function grinds(n) {
  87. inputShape = currentOpr;
  88. while (inputShape > bestShape) {
  89.  
  90. inputShape = grind(inputShape)
  91. if (inputShape > bestShape) {
  92. currentOpr = inputShape;
  93. counterGrind++;
  94. flag = true;
  95. }
  96. }
  97.  
  98. return currentOpr;
  99.  
  100. }
  101. function etchs(n) {
  102. inputShape = currentOpr;
  103. while (inputShape > bestShape) {
  104.  
  105. inputShape = etch(inputShape)
  106. if (inputShape > bestShape || xRay(inputShape) >= bestShape) {
  107. currentOpr = inputShape;
  108. counterEtch++;
  109. flag = true;
  110. }
  111. }
  112.  
  113. return currentOpr;
  114. }
  115. function xRayOnlyOnce(n) {
  116. inputShape = currentOpr;
  117. inputShape = xRay(inputShape)
  118. currentOpr = inputShape;
  119. console.log(`X-ray x${1}`);
  120. return currentOpr;
  121. }
  122.  
  123. }
  124. }
  125. solve([1375, 50000]);
  126. // solve([1000, 4000, 8100]);
  127. // solve([1000, 1555]);
  128. //solve([100, 99])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement