3 ms·
> Something I'd like people to consider is simply taking the middle value. > This supports any crazy rationale you might have for a particular order, and it is
by thaumasiotes 9y ago
> Something I'd like people to consider is simply taking the middle value.
> This supports any crazy rationale you might have for a particular order, and it is resistant to a lot of bugs you're likely to make since the code isn't particularly repetitive no matter what language you use. Oh and it doesn't have any comparison operators either.
Most of your examples seem to call a "sort" function. Are you sure you're not using any comparisons?
- geocar 9y agoThe thing to focus on in the mental load. What are you more likely to get right? a = sort(x,y,z); return a[1] or something like this? if(x >= y && x =< z) return x; if(y >= x && y =< z) return y; if(z >= x && z =< y) return z; if(x >= z && x =< y) return x; if(y >= z && y =< x) return y; if(z >= y && z =< x) return z; …
- thaumasiotes 9y agoreturn max(low, ( min(val, high) )); Still hard to avoid comparisons.