3 ms·
Guess it depends on how you define "simplest"? x / 2 + y / 2 + ((x & 1) + (y & 1)) / 2
by dukoid 4y ago
Guess it depends on how you define "simplest"?
x / 2 + y / 2 + ((x & 1) + (y & 1)) / 2
- Jensson 4y agoOr x / 2 + y / 2 + (x & y & 1) Edit: This is the same you wrote, but it gets the wrong number for negative values, for negative ints the rounding will go up and not down.
- nerdponx 4y agoAnd this is exactly why I like to use higher level programming languages. Let someone smart figure all this out for me, and give me (grug) a generic binary search routine that works on arbitrary collections of arbitrary ordered things.