Ten books are arranged in a row on a shelf. How many ways can this be done if one particular book A must always be to the left, but not necessarily immediately to the left, of another book B?


In [20]:
import itertools

In [23]:
books = 'ABCDEFGHIJ'

total = 0
correct_perm = 0
for perm in itertools.permutations(books):
    total += 1
    if perm.index('A') < perm.index('B'):
        correct_perm += 1

print(correct_perm)
print(total)


1814400
3628800

In [ ]: