12 May 2017

Candles

My solution:
int candles(int candlesNumber, int makeNew) 
{
    var sum = candlesNumber;
    while (candlesNumber >= makeNew)
    {
        sum += candlesNumber / makeNew;
        candlesNumber = candlesNumber / makeNew + (candlesNumber - candlesNumber / makeNew * makeNew);
    }

    return sum;
}

Previous Next