You are viewing a single comment's thread. Return to all comments →
Why not ?
static int numberOfChocolates(int money, int price, int bonus) { int chocolades = money / price; MainAndRest accumulated = accumulate(chocolades, bonus); if (accumulated.rest >= bonus) { MainAndRest accumulatedRests = accumulate(accumulated.rest, bonus); int result = chocolades + accumulated.main + accumulatedRests.main; return result; } else { int result = chocolades + accumulated.main; return result; } } static class MainAndRest { int main; int rest; public MainAndRest(int main, int rest) { this.main = main; this.rest = rest; } } static MainAndRest accumulate(int subMoney, int bonus) { int main = subMoney / bonus; int rest = subMoney % bonus; if ((main + rest) < bonus) { return new MainAndRest(main, rest); } else { MainAndRest sub = accumulate(main, bonus); return new MainAndRest(main + sub.main, rest + sub.rest); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Chocolate Feast
You are viewing a single comment's thread. Return to all comments →
Why not ?