买啤酒

啤酒2块钱一瓶,两个瓶身可以兑换一瓶啤酒,4个瓶盖可以兑换一瓶啤酒,10块钱能买到多少啤酒???

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var Beer = function(){
this.price = 2
this.buy = function(money){
var count = 0, currentCount = 0,
tempMoney = money, currentCap = 0, currentBody = 0
while(tempMoney > this.price){
currentCount = parseInt(tempMoney / this.price)
count += currentCount
currentCap += currentCount
currentBody += currentCount
tempMoney = tempMoney - currentCount * this.price
tempMoney += (currentCap - currentCap % 4) /2
tempMoney += currentBody - currentBody % 2
currentCap = currentCap % 4
currentBody = currentBody % 2
}
return count
}
}
-------------本文结束感谢您的阅读-------------