Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //11. Bitcoin "Mining"
- function bitcoinMining(arr) {
- let workArr = arr
- let sumBitcoins = 0
- let sumLeva = 0
- let flagFirst = false
- let dayFirstBitcoin = 0
- //0, < не работи, ама защо?
- for (let i = 1; i <= workArr.length; i++) {
- if (i % 3 === 0)
- workArr[i - 1] *= 0.7
- sumLeva += workArr[i - 1] * 67.51
- if (sumLeva >= 11949.16) {
- if (!flagFirst) {
- flagFirst = true
- dayFirstBitcoin = i
- }
- let bitcoinTmp = ~~(sumLeva / 11949.16)
- sumBitcoins += bitcoinTmp
- sumLeva = sumLeva - bitcoinTmp * 11949.16
- }
- }
- console.log(`Bought bitcoins: ${sumBitcoins}`)
- if (flagFirst)
- console.log(`Day of the first purchased bitcoin: ${dayFirstBitcoin}`)
- console.log(`Left money: ${sumLeva.toFixed(2)} lv.`)
- }
- bitcoinMining0(
- [100, 200, 300]
- )
- bitcoinMining0(
- [50, 100]
- )
- bitcoinMining0(
- [3124.15, 504.212, 2511.124]
- )
- function bitcoinMining0(arr) {
- 'use strict'
- let workArr = arr
- let sumBitcoins = 0
- let sumLeva = 0
- let flagFirst = false
- let dayFirstBitcoin = 0
- for (let i = 0; i < workArr.length; i++) {
- if ((i + 1) % 3 === 0)
- workArr[i] *= 0.7
- sumLeva += workArr[i] * 67.51
- if (sumLeva >= 11949.16) {
- if (!flagFirst) {
- flagFirst = true
- dayFirstBitcoin = i + 1
- }
- let bitcoinTmp = ~~(sumLeva / 11949.16)
- sumBitcoins += bitcoinTmp
- sumLeva = sumLeva - bitcoinTmp * 11949.16
- }
- }
- console.log(`Bought bitcoins: ${sumBitcoins}`)
- if (flagFirst)
- console.log(`Day of the first purchased bitcoin: ${dayFirstBitcoin}`)
- console.log(`Left money: ${sumLeva.toFixed(2)} lv.`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement