How to use the PERMUT function
The PERMUT function returns the number of permutations for a set of elements that can be selected from a larger number of elements. The internal order of the elements is important in permutations.
Table of Contents
1. Introduction
What is a permutation?
A permutation is an arrangement of a set of items in a specific order where the order matters. In other words, permutations are the different ways in which a collection of distinct items can be arranged taking into account the order of the items.
For example, consider the set of letters {A, B, C}. The possible permutations of this set are:
ABC, ACB, BAC, BCA, CAB, and CBA
Each of these arrangements is a different permutation because the order of the items is different.
How is the number of permutations calculated?
The number of permutations of a set of n distinct items, taken r at a time, is given by the formula:
nPr = n! / (n - r)!
n! - (read as "n factorial") represents the product of all positive integers less than or equal to n
(n - r)! - represents the product of all positive integers less than or equal to (n - r)
For example, if we want to find the number of permutations of 4 items taken 2 at a time, we would calculate:
4P2 = 4! / (4 - 2)!
(5 * 4 * 3 * 2 * 1) / (2 * 1)
24 / 2
12
So, there are 12 possible permutations of 4 items taken 2 at a time.
What is the difference between permutations and combinations?
The main difference between permutations and combinations is whether the order of the items matters or not. Permutations are used when the order matters, and combinations are used when the order does not matter.
In permutations the order of the items matters. Each different arrangement of the items is considered a distinct permutation. For example, if we have the set {A, B, C}, the permutations ABC, ACB, BAC, BCA, CAB, and CBA are all distinct because the order of the items is different in each case.
In combinations, the order of the items does not matter. Two arrangements that differ only in the order of the items are considered the same combination. For example, if we have the set {A, B, C}, the combinations AB an BA are considered the same because they contain the same items, regardless of their order.
The permutations of 3 items taken 3 at a time (all items are used) are: ABC, ACB, BAC, BCA, CAB, CBA (6 permutations)
The combinations of 3 items taken 2 at a time (selecting 2 items from 3) are: AB, AC, BC (3 combinations)
Number of permutations of n items taken r at a time:
nPr = n! / (n - r)!
Number of combinations of n items taken r at a time:
nCr = n! / (r! * (n - r)!)
What is the difference between permutations with repetition and without repetition?
In permutations without repetition each item is distinct and no item can be repeated in the arrangement. For example, if we have the set {A, B, C}, the permutations without repetition are:
ABC, ACB, BAC, BCA, CAB, CBA
Here, each item appears exactly once in each permutation.
In permutations with repetition items can be repeated in the arrangement. For example, if we have the set {A, B}, the permutations with repetition are:
AA, AB, BA, and BB.
In this case, items are repeated in some of the permutations.
2. PERMUT Function Syntax
PERMUT(number, number_chosen)
3. PERMUT Function Arguments
number | Required. A whole number larger than 0 (zero) that represents the total number of elements. |
number_chosen | Required. A whole number larger than 0 (zero) that represents the number of elements in each permutation. |
4. PERMUT Function Example
A restaurant has three spice options: chiles (A), black pepper (B), and vanilla (C). They want to create new flavors by combining two of these three spices together. The question is, how many different permutations or arrangements of two spices can be formed from the three available options? (The order matters)
To calculate the number of permutations, we can use the PERMUT function with the following arguments:
=PERMUT(n,r)
Where:
n = the total number of items (in this case, spices)
r = the number of items being selected or arranged
Formula in cell F3:
Column B, C and D demonstrate how many arrangements (permutations) there are when 2 elements are selected out of 3 elements [A, B, C]. Section 4 below demonstrates a formula that calculates all arrangements (permutations).
The six permutations are [A,B] ,[A,C] ,[B,C] , [B,A] , [C,B] and [C,A].
[A,B] - chiles and black pepper
[A,C] - chiles and vanilla
[B,C] - black pepper and vanilla
[B,A] - black pepper and chiles
[C,B] - vanilla and black pepper
[C,A] - vanilla and chiles
5. Permutations without repetition - Excel 365 formula
The following formula deletes rows that contain duplicate values, this means you need the formula in cell I3 to create permutations with repetition before using the formula in cell L3.
Formula in cell L3:
Formula in cell I3:
The formula in cell I3 is demonstrated and explained here: Create a list of permutations - Excel 365
In other words, it creates permutations without repetition based on the output from the formula above that creates permutations with repetition.
6. Find the optimal permutation - Excel Solver
A machine has five different tools named A, B, C, D, and E. The table in cell range B2:G7 shows how much time is needed to change one tool to another tool. For example, changing tool A to tool B takes 5 minutes.
In what order do we need to change tools to find the least amount of time needed? The Solver lets you change the order in cell range I3:I7 automatically, the worksheet calculates the time in cells K3:K7 based on the table.
The Solver is a built-in feature that you can use in Excel to quickly find an optimal permutation.
Cell K3 contains a sum function:
The Solver uses the value in K3 to find the optimal solution by changing numbers in I3:I7. The formula in J3:J7 returns the Tool name.
Formula in cell J3:
The INDEX function gets the tool name in C2:G2 based on the number in cell I3. The number in cell I3 changes when the Solver tries different permutations.
Formula in cell K4:
Copy this formula to cells below as far as needed.
6.1 Explaining formula
Cell K3 contains 0 (zero). The formula in K4 uses the tool name in cell J4 and the tool name in the cell above J4 which is cell J3 to find the appropriate time value in the table.
Step 1 - Calculate row
The MATCH function returns the relative position of an item in an array or cell reference that matches a specified value in a specific order.
MATCH(lookup_value, lookup_array, [match_type])
MATCH(J4, $B$3:$B$7, 0)
becomes
MATCH("B", {"A";"B";"C";"D";"E"}, 0)
and returns 2.
Step 2 - Calculate column
MATCH(J3, $C$2:$G$2, 0)
becomes
MATCH("A", {"A","B","C","D","E"}, 0)
and returns 1.
Step 6 - Get time value
The INDEX function gets a value based on a row number and column number (optional).
INDEX(array, [row_num], [column_num], [area_num])
INDEX($C$3:$G$7, MATCH(J4, $B$3:$B$7, 0), MATCH(J3, $C$2:$G$2, 0))
becomes
INDEX($C$3:$G$7, 2, 1)
becomes
INDEX(
{"-", 5, 3, 7, 4;
5, "-", 9, 11, 8;
3, 9, "-", 2, 5;
7, 11, 2, "-", 7;
4, 8, 5, 7, "-"}
, 2, 1)
and returns 5. 5 is the first value in the second row.
6.2 Setting up the Solver
- Go to tab "Data".
- Press with the left mouse button on the "Solver" button.
- Press with left mouse button on the arrow next to "Set Objective" and select cell K9. This value is the sum of all times K3:K7.
- Press with the left mouse button on the radio button named "Min" to select it. This lets the solver know that we are looking for a permutation that returns the smallest number.
- Press with left mouse button on the arrow next to "By changing variable cells" and select cells I3:I7. These cells are populated with different permutations.
- Press with the left mouse button on the "Add" button. A dialog box appears, this lets you apply constraints.
- Press with mouse on the arrow next to "Cell Reference:", then select cell range I3:I7.
- Press with mouse on the equal sign, select "dif", this lets the Solver know that all numbers in cell range I3:I7 must be different.
- Press with left mouse button on the "OK" button to return to the previous dialog box.
- Change solving method to "Evolutionary".
- Press with mouse on the check box "Make unconstrained variables Non-negative to enable it.
- Press with left mouse button on the "Solve" button to start.
- A dialog box appears, press with left mouse button on the "OK" button.
The solver found permutations iteration 4, 3, 5, 1, and 2 to be the optimal solution. In other words, this permutation returns the lowest wait time for a given set of tools.
7. List permutations with repetition - UDF
This blog post demonstrates a custom function (UDF) that creates permutations. Repetition is allowed. The custom function lets you specify the number of items to use and it will return an array of numbers.
Array formula:
To enter an array formula, type the formula in a cell then press and hold CTRL + SHIFT simultaneously, now press Enter once. Release all keys.
The formula bar now shows the formula with a beginning and ending curly bracket telling you that you entered the formula successfully. Don't enter the curly brackets yourself.
6.1 VBA Code
Function ListPermut(num As Integer) ' Permutations with repetition ' Declare variables to store intermediate calculations ' c is a counter variable for columns (elements in the permutation) ' r is a counter variable for rows (each permutation) ' p stores the total number of permutations Dim c As Long, r As Long, p As Long ' Declare a 2D array 'rng' to store the permutations Dim rng() As Long ' Calculate the total number of permutations using the formula: num^num p = num ^ num ' Resize the 'rng' array to have 'p' rows and 'num' columns ReDim rng(1 To p, 1 To num) ' Initialize the first row of the 'rng' array with consecutive numbers from 1 to 'num' For c = 1 To num rng(1, c) = 1 Next c ' Generate the remaining permutations row by row For r = 2 To p For c = num To 1 Step -1 ' If it's the last column, increment the value from the previous row If c = num Then rng(r, c) = rng(r - 1, c) + 1 ' If the current value is 0, copy the value from the previous row ElseIf rng(r, c) = 0 Then rng(r, c) = rng(r - 1, c) End If ' If the current value exceeds 'num', reset it to 1 and increment the value in the previous column If rng(r, c) = num + 1 Then rng(r, c) = 1 rng(r, c - 1) = rng(r - 1, c - 1) + 1 End If Next c Next r ' Return the 'rng' array containing all permutations ListPermut = rng End Function
7.2 How to add the user defined function to your workbook
The image above shows a macro that is not used in this article, it is only there to show you where to paste the code.
- Press Alt-F11 to open visual basic editor.
- Press with left mouse button on Module on the Insert menu.
- Copy the above user defined function.
- Paste it to the code module.
- Exit visual basic editor.
- Select sheet1.
- Select cell range A1:C27.
- Type =ListPermut(3) in formula bar and press CTRL+SHIFT+ENTER (Array formula).
If you don't know how to enter an array formula then read the detailed instructions below the image.
7.3 Example
Array formula in A3:C29:
'PERMUT' function examples
I discussed the difference between permutations and combinations in my last post, today I want to talk about two kinds […]
I got a question a while ago about permutations, in essence how to find every permutation between 0 and 9 […]
Functions in 'Statistical' category
The PERMUT function function is one of 73 functions in the 'Statistical' category.
Excel function categories
Excel categories
5 Responses to “How to use the PERMUT function”
Leave a Reply
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form
I would need to use the ListPermut function with argument 7. As I can understand it only works to a maximum of 6.
Thanks,
Antonio
I'll post an answer as soon as I can.
I'm trying to use the function for obtaining the possibilities of distributing 3 things over 5 places (repetition allowed), but the function is not workings on this option, can you please help ??
example:
A,A,B,B,C
A,A,B,B,B
A,C,B,B,A
and so on....
Thanks in advance
and also the number 5 can be changed to be from 1 to 8 but the number 3 is constant. Thank you
I have found the equation in section 4 very helpful for what I am using it for, thank you for this!
I notice that the equation only limits you to a chosen number of 4, if I wanted for example 5, then this would break the formula, but I found that is because there are more rows in the array than there are in the whole excel worksheet. For example, for PERMUTATIONA(21,5) there are 4,084,101 permutations and excel only has 1,048,576 rows.
However, I do not want all 4,084,101 permutations, but rather only the ones that sum up to a given value.
For example, I have the variables {0, 5, 10, 15, 20, 25,..., 100} that I want to find all the possible permutations with repetition where any 5 numbers sum up to 35. This should dramatically reduce the number of rows in the array to 330 possible permutations.
Is there a way to include this in the already built formula? I feel like there is but I'm struggling to figure it out.