4 ms·
This code encodes a board into [0, 6045] which fits in 13 bits: https://gist.github.com/ashdnazg/5cca7de6bac0eef4532d0c635c69184a https://gist.github.com/ashdna
by ashdnazg 3y ago
This code encodes a board into [0, 6045] which fits in 13 bits:
https://gist.github.com/ashdnazg/5cca7de6bac0eef4532d0c635c69184a https://gist.github.com/ashdnazg/5cca7de6bac0eef4532d0c635c6...
It follows the principle that one can represent a board by choosing k filled spots from 9 and then choosing k / 2 Os from k. These two combinations can be converted into an index, which can then be offset according to k to prevent collisions with indices from other ks. This offset is not pretty, but it works.
I haven't thoroughly tested my code, but the principle should work even if there's a bug or two :)
With some luck I'll find time to write a clearer explanation or a blog post.
- cbarrick 3y agoOoo exciting. Keep me posted when you write it up!