In this lesson, we will explore the concept of a permutation. A permutation is an arrangement or selection in which the order matters.
Consider this scenario: a college student has just purchased a new bookshelf for her dorm room and she has a total of n books that she wishes to arrange on the shelf. How many different ways can she arrange her books?
For the first spot on the shelf, she has n different options for the placement of a book. Next, since one book has already been placed, she now has n-1 books to place in the second spot. She will then have n-2 books for the third spot, n-3 books for the fourth spot, and so on. Suppose she has nine books in total, the arrangement of the bookshelf will look like this:
So there are:
ways to arrange the books.
For a general arrangement of n items, we have:
Here, the ! is the factorial operator.
Arranging n items without repetition results in n! a number of permutations.
Note the following identities:
- 0! = 1
- The factorial operation is undefined for numbers less than zero.
Instructions
Given the following set of letters:
How many different four-character strings can be constructed out of this set?
Assign your answer to the four_characters
variable in the accompanying Python script.
How many ways are there to arrange six chess pieces?
Assign your answer to the chess_pieces
variable.