On 04/10/2010 05:43 PM, Andrei Alexandrescu wrote:
On 04/10/2010 05:33 PM, Andrei Alexandrescu wrote:
[snip]

One more interesting detail.

Never mind that. I mistakenly used maxOR instead of maxOR2.

To summarize: best result is

total=100000000; equal=14585400 (14.5854%)

with the function:

uint maxOR(uint maxa, uint maxb) {
    uint candidate = 0;
    uint mask = 1u << 31;
    for (; mask; mask >>= 1) {
        if (maxa & mask) continue;
        auto t = candidate | mask;
        if (t <= maxb) candidate = t;
    }
    return maxa | candidate;
}

Inserting a test and a recursive call at the top keeps the result but actually slows down execution a bit.


Andrei

Reply via email to