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