Skip to content

Instantly share code, notes, and snippets.

@nothingrealhappen
Created March 3, 2016 05:54
Show Gist options
  • Save nothingrealhappen/399966e44e1744c1daaa to your computer and use it in GitHub Desktop.
Save nothingrealhappen/399966e44e1744c1daaa to your computer and use it in GitHub Desktop.
每日一题
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,
// })
// );
@Reeson1126
Copy link

cool

@ScorpiusZ
Copy link

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