Sometimes it makes things simpler (quite a a lot of things in combinatorics), other times it is a tools for nice tricks (I have no idea how I would solved these equations if it were not for generating functions, see the appendix from a Mafia game paper, https://arxiv.org/abs/1009.1031).
Generating functions, Z-transforms are indispensable in probability theory, Physics, signal processing, and now it seems for a good round of Mafia while camping with friends.
Updated the result to 80ns - thanks for flagging this. This grows with the size of the data (because more cache misses), and running the benchmark on the full billion takes a while.
[That said, on a hot production bloom filter, much can be loaded into caches anyway so it's not an entirely un-realistic scenario that some of these are cache hits]
One question: how do you manage large code bases in scratch? Is it easy to find a piece of code? Something like grepping for specific things seems difficult.
I've recently been really warming up to Scratch since one of my kids picked it up and really enjoys it. I love the built-in concurrency model - it's a bit like CSP. Gets kids to think concurrently from day 1.
Scratch is not conducive to complex (traditional) projects, which I think is sort of the appeal for seasoned programmers. For my part, I woke up one weekend knowing I had to make a recursive bisection demo in it [1]. The effort I knew it would take vs the banality and lack of game play was really funny to me in an absurd way.
Scratch lacks functions with return values, but if you hack global variables to be like registers, you can emulate them and even do recursion. At least that's how I did it. The Cartesian plane has (0,0) in the centre, which is annoying if you're used to traditional graphics.
I have a young cousin who's intimidated by making the jump from Scratch into traditional game dev. I tell him that Scratch simplifies a lot of things, but it also makes a lot of things harder if you're used to regular programming.
My younger daughter, who is pretty good at making games in Scratch is not that interested in jumping into text/code based programming. I do think Scratch makes things a lot easier and text based programming is not thar appealing to kids. I will try to start her with Pygame but even that might make it seem very arcane and not very visual.
PICO-8 [1] might be a good choice. I always consider that kids want their friends to try their games, and so being able to easily distribute to the web is awesome. They can link their game from the site [2], or with some parental help they could even serve them from their own website, which could be very empowering for a kid.
Another vote for Pico-8. It’s such an incredible little package.
The simple IDE and forced constraints makes you really focus on the basics like fun gameplay loops and minimal graphics, and the fact you can do the code, graphics, sound effects, and music all in one little program is a really smart way to teach you all different aspects of game dev.
It’s also so ridiculously easy to share your creations, outputting a simple HTML/JS combo that works perfectly on mobile and desktop even if they don’t own the program.
My daughter (12) got her start in Scratch, but had a hard time jumping into Python. She's enjoyed GBStudio, and has made a number of small games in that environment, and enjoys loading them onto a flash cart to run them on an old physical Gameboy.
https://code.org/student/middle-high has an environment that's scratch-like i the UI but the code is blockified JavaScript. (If you try to transpile a Scratch project to JavaScript using normal tools, you get an unmanageable JSON monstrosity)
It hides some of the text syntax, while still being an onramp to text-based programming.
It is really hard to search when there’s a lot of code - I just had to be pretty careful with how I laid out everything, so I roughly knew where everything was
Apart from keeping your code tidy and succinct, there's also third party extensions like https://scratchaddons.com/addons/ which can make writing code much more enjoyable - notably the `middle-click-popup`, `folders`, and `editor-devtools`. There's also an entire Debugger addon, which lets you log stuff, set breakpoints, see running threads.. Scratch Addons is awesome.
It is authoritatively debunked in Sid Meier's (excellent) memoir - there was no such integer underflow bug in Civ I, it was all a rumor that went viral. The franchise did embrace the meme, though.
I am aware that it's in his memoir, but I am not sure whether he actually went through the code to write it or just went back through his notes/memory. Or whether 2K told him to "debunk" it so he wrote some fiction (also a possibility - see Feynman's memoirs which have quite a bit of fiction in them). It was a long time ago and prior to the memoir, neither he nor any of the other developers on a Civ franchise remembered whether there was an error, and they all said as much on the record. Also, the story of an underflow was about Civ II, not Civ I. I am not necessarily convinced there is no underflow, but I am convinced that there is a plausible alternative theory.
Sorry, the intention was just to show a cool use of complex numbers, not claim this is the simplest method to generate 12 which is pretty simple, as you demonstrate.
Because sqrt is the reverse of 2^2 and 2*2 (which is 2^2 unwrapped). Though there's no direct relationship between sqrt and 2+2 other than that it happens to be equal to 2*2.
Or put differently: N = sqrt(N^2) or sqrt(N * N) for every positive N, but x = sqrt(x + x) or sqrt(x + 2) is only true for x = 2 for both or x = 0 for the first representation.
Though as I said in the rest of my comment, the 2+2 unwrap only works for N=2. So it's not a general unwrap, but rather a specific example that happens to work for N=2.
JIT is something different people sometimes define in different ways.
In this sample, when the function itself is called (not when it's decorated), analysis runs followed by LLVM codegen and execution. The examples in the blog post are minimal, but can be trivially extended to cache the JIT step when needed, specialize on runtime argument types or values, etc.
If this isn't JIT, I'm curious to hear what you consider to be JIT?