Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arrayShifts) {
- let totalCollectedMoney = 0;
- let bitcoinPurchased = 0;
- let day = 0;
- let currentDay = 0;
- for (let i = 0; i < arrayShifts.length; i++) {
- let currentGold = arrayShifts[i];
- day++;
- if (day % 3 == 0) {
- currentGold *= 0.70;
- }
- totalCollectedMoney += (67.51 * currentGold);
- if (totalCollectedMoney >= 11949.16) {
- if (currentDay == 0) {
- currentDay = day;
- }
- bitcoinPurchased += parseInt(totalCollectedMoney / 11949.16);
- totalCollectedMoney -= parseInt(totalCollectedMoney / 11949.16) * 11949.16;
- }
- }
- if (bitcoinPurchased >= 1) {
- console.log(`Bought bitcoins: ${bitcoinPurchased}`);
- console.log(`Day of the first purchased bitcoin: ${currentDay}`);
- } else {
- console.log(`Bought bitcoins: ${bitcoinPurchased}`);
- }
- console.log(`Left money: ${totalCollectedMoney.toFixed(2)} lv.`);
- }
- solve([3124.15, 504.212, 2511.124]);
- /* 1 Bitcoin = 11949.16 lv ;
- 1 g of gold = 67.51 lv.
- Output:
- · First line prints the total amount of bought bitcoins:
- "Bought bitcoins: {count}"
- · Second line prints which day you bought your first bitcoin:
- "Day of the first purchased bitcoin: {day}"
- In case you did not purchase any bitcoins, do not print the second line.
- · Third line prints the amount of money that’s left after the bitcoin purchases rounded by the second digit after the decimal point:
- "Left money: {money} lv."
- */
Advertisement
Add Comment
Please, Sign In to add comment