The Arc type is Rust’s thread-safe smart pointer, and like other pointer types in Rust (e.g., Box ), one can use the as keyword 1 to cast an Arc<MyStruct> into an Arc<dyn MyTrait> , as long as MyTrait is dyn compatible . What about casting it back from Arc<dyn MyTrait> to Arc<MyStruct> ? Well, here the plot thickens a bit. We can’t use the as keyword here, because that operation is inherently…
Every now and then, when one writes assembly code by hand, one notices opportunities for optimisation. Some are concise and elegant, it’s usually a good idea to use those. Some are complicated or convoluted, you might use them if the benefit they bring is significant. Then there are those who are outright ludicrous. You’d never use these in any production code, but if you think of one, you’re…
If you’re not familiar with the Fast Inverse Square Root algorithm, I thoroughly recommend reading about it before continuing. Not necessarily because the details are important, but because it’s such a mind-blowingly impressive hack. If you are already familiar with it, you might remember that it’s based on a magical constant (0x5F3759DF 1 ), carefully chosen to minimise the algorithm’s relative…
Super Six (a.k.a Rio and plenty of other names) is not a good game, it’s repetitive, heavily luck dependent, and repetitive. Nevertheless, it has two major qualities - it’s short and simple. These qualities translate into a much more interesting one - it’s solvable for two players! While the game itself is a mediocre subject for a blog post, the maths behind solving it are not only interesting…
The other day I happened upon a post by Chris Barrick detailing how to encode a tic-tac-toe game state in 15 bits , itself a response to an earlier post by Alejandra González detailing how to encode a tic-tac-toe state in 18 bits . In their posts, Chris and Alejandra mention 10 bits as the absolute minimum, since there are only 765 possible game states. This number, however, takes mirroring and…
Recently I’ve had my 33rd birthday and since I’m a nerd I also checked the binary representation of that number, which is 100001. OMG, I thought to myself, 33 is a palindrome in both bases! I immediately checked when my next palindromtastic birthday would be: 99 That’s a tad over my life expectancy, but arguably reachable. After that, the numbers get big quite fast. Exponentially fast. The On-Line…
Let’s say you’ve worked a few years on an open source project released under the GNU General Public License (GPL) and let’s say you’ve spied an application that is eerily similar to your project but whose owner claims no infringement of your rights. How would you find evidence for such infringement or lack thereof? Obviously, I don’t know the answer to this question as it will vary depending on…