Advertisement
dabidabidesh

Untitled

May 31st, 2020
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //11. Bitcoin "Mining"
  2. function bitcoinMining(arr) {
  3.  
  4.   let workArr = arr
  5.  
  6.   let sumBitcoins = 0
  7.   let sumLeva = 0
  8.   let flagFirst = false
  9.   let dayFirstBitcoin = 0
  10.   //0, < не работи, ама защо?
  11.   for (let i = 1; i <= workArr.length; i++) {
  12.  
  13.     if (i % 3 === 0)
  14.       workArr[i - 1] *= 0.7
  15.  
  16.     sumLeva += workArr[i - 1] * 67.51
  17.  
  18.     if (sumLeva >= 11949.16) {
  19.       if (!flagFirst) {
  20.         flagFirst = true
  21.         dayFirstBitcoin = i
  22.       }
  23.       let bitcoinTmp = ~~(sumLeva / 11949.16)
  24.       sumBitcoins += bitcoinTmp
  25.       sumLeva = sumLeva - bitcoinTmp * 11949.16
  26.     }
  27.   }
  28.   console.log(`Bought bitcoins: ${sumBitcoins}`)
  29.   if (flagFirst)
  30.     console.log(`Day of the first purchased bitcoin: ${dayFirstBitcoin}`)
  31.   console.log(`Left money: ${sumLeva.toFixed(2)} lv.`)
  32. }
  33. bitcoinMining0(
  34.   [100, 200, 300]
  35. )
  36. bitcoinMining0(
  37.   [50, 100]
  38. )
  39. bitcoinMining0(
  40.   [3124.15, 504.212, 2511.124]
  41. )
  42.  
  43. function bitcoinMining0(arr) {
  44.   'use strict'
  45.  
  46.   let workArr = arr
  47.  
  48.   let sumBitcoins = 0
  49.   let sumLeva = 0
  50.   let flagFirst = false
  51.   let dayFirstBitcoin = 0
  52.   for (let i = 0; i < workArr.length; i++) {
  53.  
  54.     if ((i + 1) % 3 === 0)
  55.       workArr[i] *= 0.7
  56.  
  57.     sumLeva += workArr[i] * 67.51
  58.  
  59.     if (sumLeva >= 11949.16) {
  60.       if (!flagFirst) {
  61.         flagFirst = true
  62.         dayFirstBitcoin = i + 1
  63.       }
  64.       let bitcoinTmp = ~~(sumLeva / 11949.16)
  65.       sumBitcoins += bitcoinTmp
  66.       sumLeva = sumLeva - bitcoinTmp * 11949.16
  67.     }
  68.   }
  69.   console.log(`Bought bitcoins: ${sumBitcoins}`)
  70.   if (flagFirst)
  71.     console.log(`Day of the first purchased bitcoin: ${dayFirstBitcoin}`)
  72.   console.log(`Left money: ${sumLeva.toFixed(2)} lv.`)
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement