Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perfect compression of sets of banko cards #9

Open
nqpz opened this issue Jul 21, 2018 · 2 comments
Open

Perfect compression of sets of banko cards #9

nqpz opened this issue Jul 21, 2018 · 2 comments

Comments

@nqpz
Copy link
Member

nqpz commented Jul 21, 2018

There are 3669688706217187500 banko cards. Say we have a set of 10000000 banko cards. How many sets of this kind exist? We can use the binomial coefficient to find this number. Then we can just compress the set of cards into an index into a virtual array of sets. However, this is a very large number, and I didn't actually succeed in just calculating it. Also, I don't think a practical implementation is doable.

But this also generalizes into our current perfect-for-one-card compression, as binom(n, 1) = n.

@athas
Copy link
Member

athas commented Jul 21, 2018

This may actually be feasible. Let N = 3669688706217187500. Now we need to compute

binom(N, k) = (N!)/((N-k)!*k!)

But what we really want is:

log2(binom(N, k)) = log2((N!)/((N-k)!*k!))
                  = log2(N!) - log2((N-k)!*k!)
                  = log2(N!) - log2((N-k)!) - log2(k!)

Now we can exploit

log2(n!) = log2(n) + log2(n-1) + ... log2(1)

But that is still slow because N is huge.

So now I am reading this blog post, which seems to suggest a better
way of approximating huge factorials: https://www.johndcook.com/blog/2010/08/16/how-to-compute-log-factorial/

So I think this is a feasible way of encoding the set, but I have not
worked it out yet.

@athas
Copy link
Member

athas commented Jul 21, 2018

Looks like this is the formula. For your example, you would need about 4500000 bits, or 548KiB. Our best algorithm (7) currently uses 766KiB to encode 100k sorted boards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants