Advertisement
Spocoman

01. Santa's Cookies

Feb 15th, 2024
1,175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function santasGifts(input) {
  2.     let cup = 140,
  3.         bigSpoon = 20,
  4.         smallSpoon = 10,
  5.         cookiesPerBox = 5,
  6.         singleCookieGrams = 25,
  7.         totalBoxes = 0,
  8.         batches = Number(input.shift());
  9.  
  10.     for (let b = 0; b < batches; b++) {
  11.         let flour = Number(input.shift()),
  12.             sugar = Number(input.shift()),
  13.             cocoa = Number(input.shift());
  14.  
  15.         let flourCups = Math.floor(flour / cup),
  16.             sugarSpoons = Math.floor(sugar / bigSpoon),
  17.             cocoaSpoons = Math.floor(cocoa / smallSpoon);
  18.  
  19.         let boxesOfCookies = Math.floor((cup + bigSpoon + smallSpoon)
  20.             * Math.min(flourCups, sugarSpoons, cocoaSpoons)
  21.             / singleCookieGrams / cookiesPerBox);
  22.  
  23.         if (boxesOfCookies == 0) {
  24.             console.log("Ingredients are not enough for a box of cookies.");
  25.         } else {
  26.             console.log(`Boxes of cookies: ${boxesOfCookies}`);
  27.             totalBoxes += boxesOfCookies;
  28.         }
  29.     }
  30.  
  31.     console.log(`Total boxes: ${totalBoxes}`);
  32.     return;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement