Skip to content

Instantly share code, notes, and snippets.

@ziphirum
Created October 8, 2014 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziphirum/0a8e638ce7bffb5a3325 to your computer and use it in GitHub Desktop.
Save ziphirum/0a8e638ce7bffb5a3325 to your computer and use it in GitHub Desktop.
/*เบียร์ 1 ขวด=2 บาท
2 ฝา แลกได้ 1 ขวด
4 ขวด แลกได้ 1ขวด
มี 20 บาท กินได้กี่ขวด(???)
*/
var cal = function(bottle, cap, money){
if (money < 2 && cap < 2 && bottle < 4) {
return 0;
}
total = Math.floor(bottle/4) + Math.floor(cap/2) + Math.floor(money/2);
money = money%2;
cap = cap%2 + total;
bottle = bottle%4 + total;
return total + cal(bottle, cap, money);
};
console.log(cal(0,0,20));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment