Problem. Among coins one is counterfeit. With a balance scale (left heavier / right heavier / equal), find it in as few weighings as possible.

VariantAnswer
fake is known to be heavier weighings: split into three near-equal groups
fake heavier or lighter, must also tell which coins with weighings: 12 coins in 3, 39 in 4
fake heavier or lighter, one extra genuine coin available: 13 coins in 3
non-adaptive (all weighings fixed in advance)same bounds, via ternary codes with balanced columns
several fakes, or a scale that returns the weight differencegroup testing / coin weighing with a spring scale (Lindström)
int heavyCoin(int n, function<int(vector<int>, vector<int>)> weigh) {   // weigh: -1 left heavier, 1 right heavier, 0 equal
    vector<int> c(n); iota(all(c), 0);
    while (sz(c) > 1) {                            // split into three near-equal groups; ceil(log3 n) weighings
        int t = (sz(c) + 2) / 3;
        vector<int> A(c.begin(), c.begin() + t), B(c.begin() + t, c.begin() + 2 * t), R(c.begin() + 2 * t, c.end());
        int r = weigh(A, B);
        c = r < 0 ? A : r > 0 ? B : R;
    }
    return c[0];
}