A combinatorial algorithm for calculating ligand binding