Combinatorics with ordering significance

combinatoricspermutations

I am trying to write Javascript code to calculate the number of possible ways in which a user can make selections given containers $A, B, C, D, E$, each with $10$ items numbered $1$ through $10$ (each container has the same items). I need help with the formula for making this calculation.

enter image description here

A user must select from at least $2$ containers ($s=2$), but can select from all of them. The order of selection is important. For example, choices a user makes could be:

  1. $B_2, C_5$ ($s=2$)
  2. $C_5, B_2$ ($s=2$)
  3. $A_9, B_1, C_3$ ($s=3$)
  4. $C_3, B_1, A_9$ ($s=3$)

My understanding is that the standard way to calculate the number of variants is $I^C$ (number of items ($I$) raised to number of containers ($C$)), which in this case would be $10^5$. I am pretty sure this is incorrect because it doesn't account for the order of selection.

How can I calculate the number of possible user selections for different values of "s," "I" and "c"?

Update: To make this clearer, assume that once a user picks an item from a container it is closed and cannot be opened. A user can select one item and only one item from each container. They MUST select from 2 containers, but can select from more as they wish. The challenge here may not be obvious and is what I am struggling with – because the ORDER of selection matters, there are more possibilities than most well-known formulas will indicate.

Best Answer

The number of permutations will be a sum that starts with $s$ factors and goes up to $5$ factors (the number of containers). In other words:

1st possibility = 50 * 40                <-- chooses from two containers
2nd possibility = 50 * 40 * 30           <-- chooses from three containers
3rd possibility = 50 * 40 * 30 * 20      <-- chooses from four containers
4th possibility = 50 * 40 * 30 * 20 * 10 <-- chooses from five containers

Total number of possibilities = 13262000

In Javascript, the code would look like this:

var CONTAINER_COUNT = 5;
var NUMBERS_PER_CONTAINER = 10;

function calculatePermutations(s) {
    var result = 0;
    for (var i = s; i <= CONTAINER_COUNT; i++) {
        var permutations = 1;
        var containersAvailable = CONTAINER_COUNT;
        var choices = 0;
        while (choices < i) {
            permutations *= containersAvailable * NUMBERS_PER_CONTAINER;
            containersAvailable--;
            choices++;
        }
        result += permutations;
    }
    return result;
}

console.log(calculatePermutations(2));

This code prints:

13262000
Related Question