Advertisement
Mitfreex

01. Cozonacs - midex06032021

Mar 6th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. /*Cozonacs - 06.03.2021 mid Exam*/
  2.  
  3. function cozonacs(input) {
  4.  
  5. let [budget, priceFlkg] = input.map(Number);
  6.  
  7. let priceEggsPack = 0.75 * priceFlkg;
  8. let priceMilk250 = (1.25 * priceFlkg) / 4;
  9. let priceCoz = priceEggsPack + priceMilk250 + priceFlkg;
  10.  
  11. let countCoz = parseInt(budget / priceCoz);
  12. let moneyleft = budget - (countCoz * priceCoz);
  13. let takedEggs = 0;
  14.  
  15. for (let i = 1; i <= countCoz; i++) {
  16.  
  17. if (i % 3 == 0) {
  18.  
  19. takedEggs += i - 2;
  20. }
  21. }
  22.  
  23. let counteggs = countCoz * 3 - takedEggs;
  24.  
  25. console.log(`You made ${countCoz} cozonacs! Now you have ${counteggs} eggs and ${moneyleft.toFixed(2)}BGN left.`);
  26. }
  27.  
  28.  
  29.  
  30.  
  31. cozonacs(['20.50', '1.25']); // => You made 7 cozonacs! Now you have 16 eggs and 2.45BGN left.
  32. cozonacs(['15.75', '1.4']); // => You made 5 cozonacs! Now you have 14 eggs and 1.31BGN left.
  33.  
  34.  
  35.  
  36. /*
  37. Create a program that calculates how much cozonacs you can make with the budget you have. First, you will receive your budget. Then, you will receive the price for 1 kg flour. Here is the recipe for one cozonac:
  38. Eggs 1 pack
  39. Flour 1 kg
  40. Milk 0.2501
  41.  
  42. The price for 1 pack of eggs is 75% of the price for 1 kg flour. The price for 11 milk is 25% more than price for 1 kg flour. Notice, that you need 0.2501 milk for one cozonac and the calculated price is for 11.
  43. Start cooking the cozonacs and keep making them until you have enough budget. Keep in mind that:
  44. • For every cozonac that you make, you will receive 3 colored eggs.
  45. • For every 3rd cozonac that you make, you will lose some of your colored eggs after you have received the usual 3 colored eggs for your cozonac. The count of eggs you will lose is calculated when you subtract 2 from your current count of cozonacs - ({currentCozonacsCount } - 2)
  46. In the end, print the cozonacs you made, the eggs you have gathered and the money you have left, formatted to the 2nd decimal place, in the following format:
  47. "You made {countOfCozonacs} cozonacs! Now you have {coloredEggs} eggs and {moneyLeft}BGN left . "
  48. Input / Constraints
  49. • On the 1s! line you will receive the budget - a real number in the range [0.0_100000.0]
  50. • On the 2nd line you will receive the price for 1 kg flour - a real number in the range [0.0_100000.0]
  51. • The input will always be in the right format.
  52. • You will always have a remaining budget.
  53. • There will not be a case in which the eggs become a negative count.
  54.  
  55. Output
  56. • Money formatted to the 2nd decimal place in the format described above.
  57.  
  58.  
  59. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement