-
-
Save nickponline/333f6d4f9ed039d8c9a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
unique = collections.defaultdict(list) | |
def simulate(sample, B, N, C, K): | |
global unique | |
if len(sample) == B: | |
counts = [0] * N | |
for s in sample: counts[s] += 1 | |
success = filter(lambda h: h >= C, counts) | |
success = len(success) >= K | |
if success: | |
h = map(str, counts) | |
h = ''.join(h) | |
unique[h].append(''.join(map(str, sample))) | |
return 1 | |
else: | |
return 0 | |
ret = 0 | |
for i in xrange(N): | |
sample.append(i) | |
ret += simulate(sample, B, N, C, K) | |
sample.pop() | |
return ret | |
B = 6 | |
N = 3 | |
C = 2 | |
K = 2 | |
sample = [] | |
print 'Total possibilities: ', N**B | |
print 'Number that have at least C copies of K elements: ', simulate(sample, B, N, C, K) | |
print 'Core problem solutions: ', len(unique.keys()) | |
print 'Bounds warning: ', B - C*K > C | |
for k in sorted(unique.keys()): | |
print '+'.join(k), '=', B, len(unique[k]), 'combinations.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment