Recent submissions

Comment · 1 year ago
The mapping after we have the leading 1's count can be done in 3 instructions (in 32-bit math) on either x86 or ARM:

    t = 0x2020c6 >> x
    return (t << (t & 31)) >> 27
Comment · 1 year ago
If you want to optimize it a little more, you can combine isLess(s, 0x20) and isChar('"') into isLess(s ^ (kOnes * 0x02), 0x21) (this works since '"' is 0x22).
Comment · 1 year ago
Thanks, fixed.
Comment · 1 year ago
The article leaves out optimizing is_leap_year. Here is an interesting version that is correct (in the Proleptic Gregorian calendar) for 0 <= year <= 102499 and takes only 3 instructions:

    ((year * 1073750999) & 3221352463) <= 126976
How this works is surprisingly complex, I am thinking of writing a whole blog post about it...
Comment · 1 year ago
Comment · 1 year ago
Comment · 2 years ago
Similarly, the eexpect table can be done in 3 instructions with with t = 0x3c783023f + i; return ((t >> (t & 63)) & 0xf0808088.
Comment · 3 years ago
I wrote a solver for Atomix (https://github.com/falk-hueffner/atomixer), a similar game. Technically, the only difference is that in Atomix the solution location is not predefined, although probably based on level design this game actually feels quite different. Since the solver just tries all solution location anyway, it would be quite simple to adapt it to this game.
Comment · 3 years ago
On a related note, almost any task around shuffling or shifting bits can be improved with xor. For example the straightforward way to remove bit i is

    mask = -1 << i;
    return (x & ~mask) | ((x >> 1) & mask);
but with xor we can do it in one less instruction:

    mask = -1 << i;
    return ((x ^ (x >> 1)) & mask) ^ x;
Comment · 4 years ago
It seems you're shifting the goal posts now. The fact that consensus criticisms are not as harsh as you'd like doesn't mean that Israel is "totally off limits". Discussions and criticisms are happening; and the fact that public opinion doesn't match yours can not only be explained by that opinion being suppressed, but also by it being wrong.
Comment · 4 years ago
I don't see that. For example, it has been the official position of the German government for at least 20 years to strongly criticize the Israeli settlements. There's regular critical reports in the press, endless TV discussions and so on. Can you name someone who has actually had to suffer negative consequences for reasonable criticism of Israel?
Comment · 4 years ago
I wrote an ingredient parser that is basically just one giant regular expression: https://github.com/falk-hueffner/metric-cooking/blob/master/...

The use case is a bit different (the task includes finding ingredients mentioned in a longer text, and it'll rather not parse something rather than parsing it wrong), but it works fairly OK and can even parse things like "3/4 cup plus 2 tablespoons packed light-brown sugar".

Comment · 5 years ago
Comment · 5 years ago
You don't necessarily need a wider type (which might be slower to work with), you can just calculate (n|1) * ((n+1)/2). Clang does something much more complicated, probably because for it is just a special case of some much more general optimization.
Comment · 5 years ago
Slightly simpler:

    c = x ^ y;
    return popcount(((c >> 1) | 0x8080808080808080) - c) & 0x8080808080808080);

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton