Created
March 3, 2016 05:54
-
-
Save nothingrealhappen/399966e44e1744c1daaa to your computer and use it in GitHub Desktop.
每日一题
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const exchange = ({ money, bottle, cap, drinked }) => { | |
if(money === 0 && bottle < 2 && cap < 4) return drinked; | |
const newDrink = parseInt(money/2) + parseInt(bottle/2) + parseInt(cap/4); | |
return exchange({ | |
money: money % 2, | |
cap: cap % 4 + newDrink, | |
bottle: bottle % 2 + newDrink, | |
drinked: drinked + newDrink, | |
}); | |
}; | |
// console.log( | |
// exchange({ | |
// money: 10, | |
// bottle: 0, | |
// cap: 0, | |
// drinked: 0, | |
// }) | |
// ); |
def beers(money,bottle,bottle_cap,sum)
return sum if money < 2 and bottle < 2 and bottle_cap < 4
bought = money/2 + bottle/2 + bottle_cap/4
return bought + beers(money%2, bottle%2+bought, bottle_cap%4+bought, sum)
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool