Divisibiility graphs in zig

After seeing this video, I’ve felt inspired to implement it in zig.
It was surprisingly easy.

Do you have any suggestions?
Defects?
Improvements?
The zig std big number stuff seemed a bit fat to add later. I’d love to also write one that can do it in a streamed fashion - you have 10^9 digits on fs, apply per digit.
I know how to get started on that streamed variant, I wouldn’t mind simply using a library that uses a widespread format.

I’m aware of at least 2 bugs/issues:

  • inputting “invalid” digits (e.g. 9 for base 2) isn’t rejected (only verify in debug build?)
  • is it correct? the tests seem to pass, but digit * pow(base, position) isn’t computed at all

source file

2 Likes