Advertisement
YavorGrancharov

Bitcoin Mining a(ExamTask)

Feb 12th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function mining(arr) {
  2.     let oneBitcoinPrice = 11949.16;
  3.     let oneGramGoldPrice = 67.51;
  4.     let firstBitcoinBought = 0;
  5.     let boughtBitcoins = 0;
  6.     let totalMoney = 0;
  7.     let diggedGold = 0;
  8.     let totalBitcoinsBought = 0;
  9.     let day = 0;
  10.     for (let i = 0; i < arr.length; i++) {
  11.         day++;
  12.         if (day % 3 !== 0) {
  13.             diggedGold += Number(arr[i]);
  14.             totalMoney += diggedGold * oneGramGoldPrice;
  15.             if (totalMoney >= oneBitcoinPrice) {
  16.                 boughtBitcoins = Math.floor(totalMoney / oneBitcoinPrice );
  17.                 if (totalMoney >= oneBitcoinPrice * boughtBitcoins) {
  18.                     totalBitcoinsBought += boughtBitcoins;
  19.                     totalMoney = totalMoney - (oneBitcoinPrice * Math.floor(totalMoney / oneBitcoinPrice));
  20.                     if (firstBitcoinBought === 0) {
  21.                         firstBitcoinBought = day;
  22.                     }
  23.                 }
  24.             }
  25.             diggedGold = 0;
  26.             boughtBitcoins = 0;
  27.         }
  28.         else {
  29.             diggedGold += (Number(arr[i]) * 0.7);
  30.             totalMoney += diggedGold * oneGramGoldPrice;
  31.             if (totalMoney >= oneBitcoinPrice) {
  32.                 boughtBitcoins = Math.floor(totalMoney / oneBitcoinPrice );
  33.                 if (totalMoney >= oneBitcoinPrice * boughtBitcoins) {
  34.                     totalBitcoinsBought += boughtBitcoins;
  35.                     totalMoney = totalMoney - (oneBitcoinPrice * Math.floor(totalMoney / oneBitcoinPrice));
  36.                     if (firstBitcoinBought === 0) {
  37.                         firstBitcoinBought = day;
  38.                     }
  39.                 }
  40.             }
  41.             diggedGold = 0;
  42.             boughtBitcoins = 0;
  43.         }
  44.     }
  45.     console.log(`Bought bitcoins: ${totalBitcoinsBought}`);
  46.     if (firstBitcoinBought > 0) {
  47.         console.log(`Day of the first purchased bitcoin: ${firstBitcoinBought}`);
  48.     }
  49.     console.log(`Left money: ${totalMoney.toFixed(2)} lv.`);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement