Hacker News new | ask | show | jobs
by oneeyedpigeon 193 days ago
I prefer data-driven programming, so a simple:

    return odd_or_evenness[n];
works for me, alongside a pretty big array.
4 comments

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!

    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.