How to write a program that counts rearrangements of a word in Python using recursion?
Description: The letters of the word "bookkeeper" can be rearranged in 151,200
ways. Of course this is far too many to write them all down. However, there are
formulas that allow us to count such things.
The number of ways to rearrange n objects in a line is given by the formula
n! = n(n −1)(n −2) ⋯ (2) 1
If m of the objects are indistinguishable, then for each distinct arrangement, there will be
exactly m! indistinguishable rearrangements, so the total number is n!/m! In our problem,
there are 10 letters (b, o, o, k, k, e, e, p, e, r), including 2 o's, 2, k's, and 3 e's. So the total
number of rearrangements is
10! / 2!2!3! = (10 ⋅ 9 ⋅ 8 ⋅ 7 ⋅ 6 ⋅ 5 ⋅ 4 ⋅ 3 ⋅ 2 ⋅ 1) / (2 ⋅ 1)(2 ⋅ 1)(3 ⋅ 2 ⋅ 1) = 151,200
In this program, I need to write a recursive function to compute factorials, and
use the function to count the number of rearrangements of the letters of words.
I need two functions.
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment