July 16, 2026, 11:56pm 1
While doing Advent of code 2015 day 13 I realized I needed to make some combinations of people around a table. Turns out this concept is called a permutation and well, one thing led to the other until I made my first library ever.
You can find it here: https://codeberg.org/T3kla/plain-changes
And it kinda does this:
| n = 1 | n = 2 | n = 3 |
|---|---|---|
| 1 | 1 2 | 1 2 3 |
| 2 1 | 1 3 2 | |
| 3 1 2 | ||
| 3 2 1 | ||
| 2 3 1 | ||
| 2 1 3 |
I had a lot of fun optimizing it. I found out many little things, like some times u32 is faster than u8 if it involves indexing, or that unwrapping an optional takes a few more nanoseconds than comparing two ints.
The biggest optimization of them all came from the inverse index array, which I have no clue if it’s mainstream to use in this algorithm but it’s basically a *3 speedup.
Help!
This is truly my first library ever and I have no clue if my setup is actually correct, since I just imitated other Zig libraries I saw in Codeberg.
If you see anything that catches your eye, I’m completely open to criticism!
Supported Zig versions
zig-0-16
alanza July 17, 2026, 12:48am 2
I remember loving the book Another Fine Math You’ve Got Me Into by Ian Stewart as a kid (although his stories are far from kid stuff!), which is, as i understand as an adult, mostly a compilation of some of his best stories as a regular columnist on mathematics for Scientific American. In that book, one of the stories features a character based on the Hunchback of Notre Dame named Quasimodulo, and “ringing the changes” is discussed at some length!
Anyway, fun trip down memory lane, cheers on your first library!
0 Comments
Log in to join the conversation.No comments yet. Be the first to share your thoughts.