Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mining(arr) {
- let oneBitcoinPrice = 11949.16;
- let oneGramGoldPrice = 67.51;
- let firstBitcoinBought = 0;
- let boughtBitcoins = 0;
- let totalMoney = 0;
- let diggedGold = 0;
- let totalBitcoinsBought = 0;
- let day = 0;
- for (let i = 0; i < arr.length; i++) {
- day++;
- if (day % 3 !== 0) {
- diggedGold += Number(arr[i]);
- totalMoney += diggedGold * oneGramGoldPrice;
- if (totalMoney >= oneBitcoinPrice) {
- boughtBitcoins = Math.floor(totalMoney / oneBitcoinPrice );
- if (totalMoney >= oneBitcoinPrice * boughtBitcoins) {
- totalBitcoinsBought += boughtBitcoins;
- totalMoney = totalMoney - (oneBitcoinPrice * Math.floor(totalMoney / oneBitcoinPrice));
- if (firstBitcoinBought === 0) {
- firstBitcoinBought = day;
- }
- }
- }
- diggedGold = 0;
- boughtBitcoins = 0;
- }
- else {
- diggedGold += (Number(arr[i]) * 0.7);
- totalMoney += diggedGold * oneGramGoldPrice;
- if (totalMoney >= oneBitcoinPrice) {
- boughtBitcoins = Math.floor(totalMoney / oneBitcoinPrice );
- if (totalMoney >= oneBitcoinPrice * boughtBitcoins) {
- totalBitcoinsBought += boughtBitcoins;
- totalMoney = totalMoney - (oneBitcoinPrice * Math.floor(totalMoney / oneBitcoinPrice));
- if (firstBitcoinBought === 0) {
- firstBitcoinBought = day;
- }
- }
- }
- diggedGold = 0;
- boughtBitcoins = 0;
- }
- }
- console.log(`Bought bitcoins: ${totalBitcoinsBought}`);
- if (firstBitcoinBought > 0) {
- console.log(`Day of the first purchased bitcoin: ${firstBitcoinBought}`);
- }
- console.log(`Left money: ${totalMoney.toFixed(2)} lv.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement