(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 & ls] ls sub-list (combos ls)] (concat sub-list (for [x l, y sub-list] (cons x y)))))) Now (count (combos locks)) => 72 ... as expected. There are better ways to depict the problem space, but this'll surely do.