3 ms·
I prefer data-driven programming, so a simple: return odd_or_evenness[n]; works for me, alongside a pretty big array.
by oneeyedpigeon 11mo ago
I prefer data-driven programming, so a simple:
return odd_or_evenness[n];
works for me, alongside a pretty big array.
- projektfu 11mo agoYou might like the IBM 1620. https://en.wikipedia.org/wiki/IBM_1620#Anecdotes https://en.wikipedia.org/wiki/IBM_1620#Anecdotes
- enopod_ 11mo agoThis is the way.
- layer8 11mo agoWith 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!
- Zambyte 11mo agoconst 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.