Learn

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:

9 8 7 6  1\underline{9} \ \underline{8} \ \underline{7} \ \underline{6}\ \ldots \ \underline{1}

So there are:

9×8×7××1=362,8809 \times 8 \times 7 \times \ldots \times 1 = 362,880

ways to arrange the books.

For a general arrangement of n items, we have:

n(n1)(n2)1=n!n(n-1)(n-2) \ldots 1 = n!

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

1.

Given the following set of letters:

Letters={A, B, C, D}Letters = \left \{ A, \ B, \ C, \ D \right \}

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.

2.

How many ways are there to arrange six chess pieces?

C={pawn, knight, bishop, rook, queen, king}C = \left \{ pawn, \ knight, \ bishop, \ rook, \ queen, \ king \right \}

Assign your answer to the chess_pieces variable.

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?