DEV Community

Discussion on: Daily Challenge #108 - Find the Counterfeit Coin

Collapse
 
dwilmer profile image
Daan Wilmer

Good one! This changes it to the following code:

function numWeightings($numCoins) {
    if ($numCoins <= 1) {
        return 0;
    }


    return numWeightings(ceil($numCoins / 3)) + 1;
}

which is equal to

function numWeightings($numCoins) {
    return ceil(log($numCoins, 3));
}