I prefer data-driven programming, so a simple:
return odd_or_evenness[n];
works for me, alongside a pretty big array.You might like the IBM 1620.
const odd_or_evenness = comptime blk: {
var buf: [16]bool = undefined;
var is_even = false;
for (&buf) |*b| {
b.* = is_even;
is_even = !is_even;
}
break :blk buf;
};
This looks like a promising strategy.This is the way.
With data-driven programming, I would have expected an SQL table containing all the precomputed results. Unless you carelessly add an index, it has the same asymptotic performance!