Clear questions and runnable code
get the best and fastest answer
Re^6: Challenge: 8 Letters, Most Wordsby LanX (Chancellor)
|on Oct 05, 2013 at 13:19 UTC||Need Help??|
> In other words, choose all combinations of any 8 chars out of the following string: "aaaabbbcccddddeeeeffffgggghhhiiijjkkkllllmmmnnnnoooopppqrrrrssssstttuuuuvvwwwxxyyyzzzz"
The point is to handle duplications, if all letters are unique the answer is simply (26 over 8)
Reasoning is simple, it calculates all binary vectors of length 26 with exactly 8 1-bits.
But with duplications its more complicated, e.g. 4 out of "aabcd" is not (5 over 4)=5
cause the first 2 solutions are identical.
Generating all combinations and filtering the unique once is normally not very clever, cause the overhead can be enormous.
And I'm stuck finding a formula which calculates all unique solutions, but generating is easier, just don't allow bitvectors with "gaps" between identical letters:
I will update this post with a loop generating all possibilities soon.
indeed L~R's number of 12461993 possibilities is correct
The following (non-optimized) code took 3 minutes to calculate them:
( addicted to the Perl Programming Language)