logoalt Hacker News

oneeyedpigeonlast Friday at 12:10 PM4 repliesview on HN

I prefer data-driven programming, so a simple:

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

Replies

layer8last Friday at 2:15 PM

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!

Zambytelast Friday at 2:19 PM

    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.
enopod_last Friday at 12:38 PM

This is the way.