Created
April 21, 2016 16:17
-
-
Save chris-wood/f37b1061ed974d76d8ee18e6ce726117 to your computer and use it in GitHub Desktop.
number of unique names (algorithmically)
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
B = 8 # 8 bytes for the fixed name length | |
total = 0 # accumulator for the number of names | |
for b in range(1, B + 1): | |
# Compute the number of unique partitions for all possible values of k | |
l = [0] * b | |
partition_total = 0 | |
for k in range(1, b): | |
partition_total += num_partitions(l, k) | |
# Multiply the partition total by the number of possible names of length b | |
num_unique = 2 ** (8 * b) | |
total += (partition_total * num_unique) | |
# Debug | |
print "For b=%d, partition_total=%d" % (b, partition_total) | |
print "For b=%d, num_unique=%d" % (b, num_unique) | |
print "Total: %d" % (total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment