When enumerating a multiset, we are sometimes interested in the relative order of some members of the set. Take for example the problem of figuring out how many ways we can order the letters in the word APPLE such that the two P’s appear next to one another (ELPPA for example). The set of letters in this problem is S = {A, P, P, L, E} which is a set of cardinality five. Since we want the two P’s together, we can treat them as a single element PP. The set now looks like this: S = {A, PP, L, E} of cardinality four. We would enumerate this using the same technique as we did in Exercise 2 to obtain an answer of:

4!=244! = 24

There are 24 possible permutations of the word APPLE in which the two P’s are next to one another.



A box contains three red balls, three blue balls, and three green balls. How many ways can you arrange the nine balls such that you have two red balls and one green ball appearing together? Assume initially that each color is distinct and you want them to appear in the order red-red-green (RRG). Set the variable nine_balls_1 to your answer.


All balls of the same color are not distinct! How would you correct your previous calculation to account for this fact? Set the variable nine_balls_2 to your answer.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?