// https://goo.gl/bU3BVR
// 若手上有100,要盡量把錢花掉,糖果一顆11、餅乾一塊13
var MoneyIhave = 100
var suger = 11
var piece = 13
var totalMoney = new Array()
for (i=0, totalMoney[i]=0 ; i<=MoneyIhave/suger ; i++){
totalMoney[i] = suger*i
for(totalMoney[i], j=0; totalMoney[i] <= MoneyIhave; j++){
totalMoney[i] = suger*i + piece*j
if ( totalMoney[i] <= MoneyIhave ){
No_suger = i
No_piece = j
answer = totalMoney[i]
}
}
document.write("i=",No_suger,",j=",No_piece,",totalMoney=",answer,"<br>")
document.write("--------------","<br>")
}