How to find number of permutations of 1-N length, each [1-N] with k values This imaginary problem involves a vector of length 5, with each value to be selected from a unique range of values. 

A real-world example might include 5 different single-digit combination locks.

How many different ways could I lock a single gate, assuming that I can use any number of locks?

Assuming that each lock takes values ([1-3], [1-3], [1-3], [1-3], [1-3]) There would be 3^5 ==  243 possible combinations. But I'm also interested in calculating the total number of combinations possible by using subsets of the 5 locks, so adding the solution for each combination of four locks, each combination of 3 locks and so on. The solution would also ideally be generalisable so that each list of values can differ i.e. ([1-2], [1-10], [A-C] ... )

Does there exist a mathematical solution to this problem?



edit: 

In the main, the question is about a general purpose mathematical solution. For example, to find the number of combination of a set of length (3), one uses 3! ie. 6 combinations of [1,2,3].

I was wondering if there exists a general purpose solution to the above scenario. If not, I would think it could be possible to program something to recurse over the possibilities, which I guess is why I decided to post it here first as my search for a mathematical solution came up empty handed.



Some examples of inputs and outputs as requested:

input = [A,B,C] [1,2,3,4,5] [G,H]

output combinations are all possible combinations of those three lists, without needing to sample all three lists. Note combinations, hence [A1G] == [G1A]

i.e. (this is not all the combinations):
A
B
C
A1
A2
A3
...
C4
C5
A1G
A1H
A2G
A2H
...
C5G
C5H
...
1
2
3
4
5
1G
1H
.
.
5G
5H
..
G
H
(Your lock values are all distinct. We could instead consider the locks distinct.)

We add a nil value to each lock, representing the lock not being included. Using your example, we get ...

input = [A,B,C,nil] [1,2,3,4,5,nil] [G,H,nil]


... to choose from. There are ...

$$4 \times 6 \times 3 = 72 $$

... ways to do this. 

In general, from sets $Locks$, there are ...(

$$\prod_{l \in Locks} (\vert l \vert + 1)$$

... ways. 



So far, so mathematical. Now let's generate the possibilities. I'll have to use a programming language. My choice is Clojure, a Lisp. We should be able to at least verify the above result. 

(def locks '[[A,B,C] [1,2,3,4,5] [G,H]])

(defn combos [ls]
  (if (empty? ls)
    [()]
    (let [[l &amp; ls] ls
          sub-list (combos ls)]
      (concat
        sub-list
        (for [x l, y sub-list] (cons x y))))))


Now 

(count (combos locks))
=&gt; 72


... as expected. 

There are better ways to depict the problem space, but this'll surely do.