喂喂,這是個超簡單的問題吧?KISS!
<meta charset='utf-8'><script>
function exchange( bottle, cap ) {
if ( cap === undefined ) return alert( '共 ' + ( bottle + exchange( bottle, bottle ) ) + ' 支酒' );
var newBottles = ~~( cap/4 ) + ~~( bottle/2 );
alert( "現有 " + bottle + " 酒瓶, " + cap + " 蓋子, 可換 " + newBottles + " 支酒" );
return newBottles ? newBottles + exchange( bottle % 2 + newBottles, cap % 4 + newBottles ) : 0;
}
exchange( 10/2 );
</script>