Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- let price = 0;
- let oneGramGoldPrice = 67.51;
- let bitcoinPrice = 11949.16;
- let countBitc = 0;
- let dayOfFirstBuy = 0;
- let counter = 0;
- let moneyLeft = 0;
- let goldGrams = 0;
- let counter2 = 0;
- for (gold of arr) {
- counter2++;
- if (counter2 % 3 === 0) {
- goldGrams = gold;
- goldGrams = goldGrams - goldGrams * (30 / 100);
- price += goldGrams * oneGramGoldPrice;
- } else {
- price += gold * oneGramGoldPrice;
- }
- while (bitcoinPrice <= price) {
- moneyLeft = price - bitcoinPrice;
- price = moneyLeft;
- if (counter === 0) {
- counter++;
- dayOfFirstBuy = counter2;
- }
- countBitc++;
- }
- }
- if (counter === 0) {
- moneyLeft = price;
- }
- console.log(`Bought bitcoins: ${countBitc}`);
- if (counter > 0) {
- console.log(`Day of the first purchased bitcoin: ${dayOfFirstBuy}`);
- }
- console.log(`Left money: ${moneyLeft.toFixed(2)} lv.`);
- // 10531.78 lv.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement