Implement a function that takes a list that consists of 0, 1 or 2, the list is called "pattern". Your job is to return all possible lists that match the pattern.
- 0 matches 0
- 1 matches 1
- 2 matches 0 and 1
Examples:
f([0, 1, 1]) == [[0, 1, 1]]
f([0, 2, 0, 2]) == [[0, 0, 0, 0], [0, 1, 0, 0], [0, 1, 0, 1], [0, 0, 0, 1]]
f([2, 1, 0]) == [[0, 1, 0], [1, 1, 0]]
Order does not matter, you can use a {set} data structure instead.
You cannot use regular expressions or other string pattern matching mechanisms. You cannot use a brute-force search.
Shortest solution wins.