Advertisement
Iv555

Untitled

Mar 7th, 2023
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. function radioCrystals(input) {
  2. let desired = input[0];
  3. let chops = input.slice(1);
  4. let output = '';
  5. for (let index = 0; index < chops.length; index++) {
  6. let currentChop = chops[index];
  7. let operations = {
  8. 'cut': 0,
  9. 'lap': 0,
  10. 'grind': 0,
  11. 'etch': 0,
  12. 'x-ray': 0,
  13. }
  14. output += `Processing chunk ${currentChop} microns\n`;
  15. while (currentChop / 4 >= desired) {
  16. currentChop /= 4;
  17. operations['cut']++;
  18. }
  19.  
  20. currentChop = Math.floor(currentChop);
  21. output += operations['cut'] > 0 ? `Cut x${operations['cut']}\nTransporting and washing\n` : '';
  22.  
  23. while (currentChop * 0.80 >= desired) {
  24. currentChop *= 0.80;
  25. operations['lap']++;
  26. }
  27. currentChop = Math.floor(currentChop);
  28. output += operations['lap'] > 0 ? `Lap x${operations['lap']}\nTransporting and washing\n` : '';
  29.  
  30. while (currentChop - 20 >= desired) {
  31. currentChop -= 20;
  32. operations['grind']++;
  33. }
  34. currentChop = Math.floor(currentChop);
  35. output += operations['grind'] > 0 ? `Grind x${operations['grind']}\nTransporting and washing\n` : '';
  36.  
  37. while (currentChop - 2 >= desired) {
  38. currentChop -= 2;
  39. operations['etch']++;
  40. }
  41. currentChop = Math.floor(currentChop);
  42.  
  43. if (currentChop > desired || currentChop + 1 === desired) {
  44. currentChop += 1;
  45. operations['x-ray']++;
  46. }
  47. if (currentChop - desired >= 2) {
  48. currentChop -= 2;
  49. operations['etch']++;
  50. }
  51. output += operations['etch'] > 0 ? `Etch x${operations['etch']}\nTransporting and washing\n` : '';
  52. output += operations['x-ray'] === 1 ? `X-ray x1\n` : '';
  53. output += `Finished crystal ${desired} microns\n`;
  54. }
  55. console.log(output.trimEnd())
  56. }
  57.  
  58. radioCrystals([1375, 50000]);
  59. radioCrystals([1000, 4000, 8100]);
  60. radioCrystals([100, 99])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement