Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (input) {
- let needMicrons = input[0];
- let cut = 0;
- let lap = 0;
- let grind = 0;
- let etch = 0;
- let xray = 0;
- for (let i = 0; i < input.length - 1; i++) {
- let curentCrystal = input[i+1];
- while (curentCrystal > needMicrons) {
- if (curentCrystal / 4 >= needMicrons) {
- curentCrystal /= 4;
- cut++;
- } else if (curentCrystal - (curentCrystal * 0.20) >= needMicrons) {
- if (lap == 0) {
- curentCrystal = Math.floor(curentCrystal);
- }
- curentCrystal -= curentCrystal * 0.20;
- lap++;
- } else if (curentCrystal - 20 >= needMicrons) {
- if (grind == 0) {
- curentCrystal = Math.floor(curentCrystal);
- }
- curentCrystal -= 20;
- grind++;
- } else if (curentCrystal - 2 >= needMicrons) {
- if (etch == 0) {
- curentCrystal = Math.floor(curentCrystal);
- }
- curentCrystal -= 2;
- etch++;
- } else if (xray == 0){
- curentCrystal = Math.floor(curentCrystal);
- curentCrystal++;
- xray++;
- }
- }
- console.log(`Processing chunk ${input[i+1]} microns`)
- if (cut > 0) {
- console.log(`Cut x${cut}`);
- console.log(`Transporting and washing`);
- cut = 0;
- }
- if (lap > 0) {
- console.log(`Lap x${lap}`);
- console.log(`Transporting and washing`);
- lap = 0;
- }
- if (grind > 0) {
- console.log(`Grind x${grind}`);
- console.log(`Transporting and washing`);
- grind = 0;
- }
- if (etch > 0) {
- console.log(`Etch x${etch}`);
- console.log(`Transporting and washing`);
- etch = 0;
- }
- if (xray > 0) {
- console.log(`X-ray x${xray}`);
- xray = 0;
- }
- console.log(`Finished crystal ${needMicrons} microns`)
- }
- }
- solve([1000, 4000, 8100]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement