Ranking between two strings For the word "BOOKKEEPER". It's sorted representation is "BEEEKKOOPR" How can I find the different permutations of the word between "BEEEKKOOPR" and "BOOKKEEPER"?
similar example:
For "BBAA" 
AABB - 1
ABAB - 2
ABBA - 3
BAAB - 4
BABA - 5
BBAA - 6

6 - 1 = 5 So there are 5 words before "BBAA"
"BEEEKKOOPR" would be number 1. "BOOKKEEPER" would be some distance away. I'm not sure how to go about this as I believe this is a combinatorics problem and I don't have much experience with the subject. 
 A: discounting B (which must lead every string), there are 9 symbols.
we can rank
(B = 0)
E = 1
K = 2
O = 3
P = 4
R = 5
now, for BOOKKEEPER
we can include every combination that gives 2 or fewer for the first digit: 
3 "1"s and 2 "2"s
5 * 8!
+ 
all valid combinations where 3 is the first digit
if 3 is the first digit, and 2 or fewer is the second digit, include all combinations, so:
5 * 8!
+
4 * 7!
+ 
all valid combinations starting with 33
if the next digit is a 1, of which there are 3, include it
5 * 8!
+
4 * 7!
+ 
3 * 6!
+ 
all valid combinations 332
if the next digit is a 1, of which there are 3, include it
5 * 8!
+ 
4 * 7!
+ 
3 * 6!
+ 
3 * 5!
+ 
all valid combinations 3322
the next digit must be a 1, and the digit after that must be a 1, so really its
all valid combinations 332211
if the next digit is 1, include all values: 
5 * 8!
+ 
4 * 7!
+ 
3 * 6!
+ 
3 * 5!
+ 
2!
+ 
all valid combinations 3322114
of which there is only 1: 332211415 ie, BOOKEEPER
so the number of values below BOOKEEPER is
5*8! + 4*7! + 3*6! + 3*5! + 2! + 1, and between BOOKEEPER AND BEEEKKOOPR
is
5*8! + 4*7! + 3*6! + 3*5! + 2!
since we just subtract off the extra 1.
At least, that's how I'd solve it.
