Advertisement
ErolKZ

Untitled

Sep 18th, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. function solve(arr) {
  2.  
  3.  
  4. let price = 0;
  5.  
  6. let oneGramGoldPrice = 67.51;
  7.  
  8. let bitcoinPrice = 11949.16;
  9.  
  10. let countBitc = 0;
  11.  
  12. let dayOfFirstBuy = 0;
  13.  
  14. let counter = 0;
  15.  
  16. let moneyLeft = 0;
  17.  
  18. let goldGrams = 0;
  19.  
  20. let counter2 = 0;
  21.  
  22.  
  23.  
  24. for (gold of arr) {
  25.  
  26.  
  27. counter2++;
  28.  
  29. if (counter2 % 3 === 0) {
  30.  
  31. goldGrams = gold;
  32.  
  33. goldGrams = goldGrams - goldGrams * (30 / 100);
  34.  
  35. price += goldGrams * oneGramGoldPrice;
  36.  
  37. } else {
  38.  
  39. price += gold * oneGramGoldPrice;
  40.  
  41. }
  42.  
  43.  
  44. while (bitcoinPrice <= price) {
  45.  
  46. moneyLeft = price - bitcoinPrice;
  47.  
  48. price = moneyLeft;
  49.  
  50.  
  51.  
  52. if (counter === 0) {
  53.  
  54. counter++;
  55.  
  56. dayOfFirstBuy = counter2;
  57.  
  58. }
  59.  
  60. countBitc++;
  61.  
  62. }
  63.  
  64. }
  65.  
  66.  
  67. if (counter === 0) {
  68.  
  69. moneyLeft = price;
  70.  
  71. }
  72.  
  73.  
  74. console.log(`Bought bitcoins: ${countBitc}`);
  75.  
  76. if (counter > 0) {
  77.  
  78. console.log(`Day of the first purchased bitcoin: ${dayOfFirstBuy}`);
  79.  
  80. }
  81.  
  82. console.log(`Left money: ${moneyLeft.toFixed(2)} lv.`);
  83.  
  84. // 10531.78 lv.
  85.  
  86.  
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement