re: Daily Challenge #108 - Find the Counterfeit Coin VIEW POST

TOP OF THREAD FULL DISCUSSION
re: It can be actually done in much fewer measurements by dividing the pile in thirds. This way even in the worst scenario you reduce the number of coi...
 

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));
}
code of conduct - report abuse