Advertisement
EntropyStarRover

11. Bitcoin "Mining"

May 16th, 2019
699
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function mining(input){
  2.  let days=input.length;
  3.  
  4.  let totalMoney=0;
  5.  let dayOfFirstBitcoin=0;
  6.  let bitcoinsBought=0;
  7.  
  8.  
  9.  for (let i=1; i<=days; i++){
  10.    
  11.      let dailyGrams=input.shift();
  12.      if (i%3==0){
  13.         dailyGrams=dailyGrams*0.70;
  14.     }
  15.      totalMoney+=dailyGrams*67.51;
  16.  
  17.  
  18.      if (totalMoney>=11949.16){
  19.          dayOfFirstBitcoin=i;
  20.       }
  21.  }
  22.  
  23. bitcoinsBought=Math.floor(totalMoney/11949.16);
  24. let moneySpent=bitcoinsBought*11949.16;
  25. let moneyLeft=totalMoney-moneySpent;
  26.  
  27.  console.log(`Bought bitcoins: ${Math.floor(bitcoinsBought)}`);
  28.  if (dayOfFirstBitcoin>0){
  29.  console.log(`Day of the first purchased bitcoin: ${dayOfFirstBitcoin-1}`);
  30.  }
  31.  console.log(`Left money: ${moneyLeft.toFixed(2)} lv.`);
  32.    
  33. }
Advertisement
RAW Paste Data Copied
Advertisement