Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- for (let i = 1; i < arr.length; i++) {
- let inputShape = [];
- inputShape = arr[i];
- let bestShape = arr[0];
- let currentOpr = 0;
- let cut = x => x / 4;
- let counterCut = 0;
- let lap = x => x - x * 0.20;
- let counterLaps = 0;
- let grind = x => x - 20;
- let counterGrind = 0;
- let etch = x => x - 2;
- let counterEtch = 0;
- let xRay = x => x + 1; //only ONCE
- let flag = false;
- console.log(`Processing chunk ${arr[i]} microns`);
- cuts(currentOpr);
- if (flag) {
- currentOpr = Math.floor(currentOpr);
- console.log(`Cut x${counterCut}`);
- console.log(`Transporting and washing`);
- flag = false;
- }
- laps(currentOpr);
- if (flag) {
- currentOpr = Math.floor(currentOpr);
- console.log(`Lap x${counterLaps}`);
- console.log(`Transporting and washing`);
- flag = false;
- }
- grinds(currentOpr);
- if (flag) {
- currentOpr = Math.floor(currentOpr);
- console.log(`Grind x${counterGrind}`);
- console.log(`Transporting and washing`);
- flag = false;
- }
- etchs(currentOpr);
- if (flag) {
- currentOpr = Math.floor(currentOpr);
- console.log(`Etch x${counterEtch}`);
- console.log(`Transporting and washing`);
- flag = false;
- }
- if ((inputShape + 1) === bestShape) {
- xRayOnlyOnce(currentOpr);
- }
- console.log(`Finished crystal ${currentOpr} microns`);
- function cuts(n) {
- currentOpr = inputShape;
- while (inputShape >= bestShape) {
- inputShape = cut(inputShape)
- if (inputShape >= bestShape) {
- currentOpr = inputShape;
- counterCut++;
- flag = true;
- }
- }
- return currentOpr;
- }
- function laps(n) {
- inputShape = currentOpr;
- while (inputShape > bestShape) {
- inputShape = lap(inputShape)
- if (inputShape > bestShape) {
- currentOpr = inputShape;
- counterLaps++;
- flag = true;
- }
- }
- return currentOpr;
- }
- function grinds(n) {
- inputShape = currentOpr;
- while (inputShape > bestShape) {
- inputShape = grind(inputShape)
- if (inputShape > bestShape) {
- currentOpr = inputShape;
- counterGrind++;
- flag = true;
- }
- }
- return currentOpr;
- }
- function etchs(n) {
- inputShape = currentOpr;
- while (inputShape > bestShape) {
- inputShape = etch(inputShape)
- if (inputShape > bestShape || xRay(inputShape) >= bestShape) {
- currentOpr = inputShape;
- counterEtch++;
- flag = true;
- }
- }
- return currentOpr;
- }
- function xRayOnlyOnce(n) {
- inputShape = currentOpr;
- inputShape = xRay(inputShape)
- currentOpr = inputShape;
- console.log(`X-ray x${1}`);
- return currentOpr;
- }
- }
- }
- solve([1375, 50000]);
- // solve([1000, 4000, 8100]);
- // solve([1000, 1555]);
- //solve([100, 99])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement