Friday, May 16, 2025

A leap year check in three instructions

 https://hueffner.de/falk/blog/a-leap-year-check-in-three-instructions.html

With the following code, we can check whether a year 0 ≤ y ≤ 102499 is a leap year with only about 3 CPU instructions:

bool is_leap_year_fast(uint32_t y) {
    return ((y * 1073750999) & 3221352463) <= 126976;
}

How does this work? The answer is surprisingly complex. This article explains it, mostly to have some fun with bit-twiddling; at the end, I'll briefly discuss the practical use.

 

Bonus link:

That article links out to this site several times that lets you input high level code like C/Ruby/Javascript/etc and see the compiled/assembly output.

https://godbolt.org/z/PWs8saMYd

Saturday, May 3, 2025

The one interview question that will protect you from North Korean fake workers

https://www.theregister.com/2025/04/29/north_korea_worker_interview_questions/

The first time in a long time I can think of a "one weird trick" style tip which is actually one weird trick that does seem like it'd be effective.

North Korean infiltrators are bagging roles worldwide throughout the year. Thousands are said to have infiltrated the Fortune 500.

They're masking IPs, exporting laptop farms to America so they can connect into those machines and appear to be working from the USA, and they are using AI – but there's a question during job interviews that never fails to catch them out and forces them to drop out of the recruitment process.

"My favorite interview question, because we've interviewed quite a few of these folks, is something to the effect of 'How fat is Kim Jong Un?' They terminate the call instantly, because it's not worth it to say something negative about that," he told a panel session at the RSA Conference in San Francisco Monday.