Pergunta

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

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a cs.stackexchange
scroll top