Let's say we have a 2-D list, like the following one:
\$ \begin{bmatrix} \color{red}{1} & \color{red}{2} & \color{red}{3} & \color{red}{4} \\ \color{blue}{5} & \color{blue}{6} & \color{blue}{7} & \color{red}{8} \\ \color{green}{9} & \color{green}{10} & \color{blue}{11} & \color{red}{12} \end{bmatrix} \$
Notice how the top row and the right column is red. For the purposes of this question, let's call this a J-bracket✝. The 2nd J-bracket is highlighted in blue, and the 3rd J-bracket is highlighted in green. Your challenge is not to find the J-brackets, but given the J-bracket list, you need to return the original 2-D list.
In many cases, there will be more than one 2-D list possible based on the J-brackets. In this case, you can return either of the possible 2-D lists, or you can return a list of the possiblities.
Let's say you are given the list [[1,2,3,4,5,6], [1,2,3,4], [1,2]]
. This means the 1st J-bracket is [1,2,3,4,5,6]
, the 2nd J-bracket is [1,2,3,4]
, and the 3rd one is [1,2]
. There are two different possible matrixes that can be created from these J-brackets:
\$ \begin{bmatrix} \color{red}{1} & \color{red}{2} & \color{red}{3} & \color{red}{4} \\ \color{blue}{1} & \color{blue}{2} & \color{blue}{3} & \color{red}{5} \\ \color{green}{1} & \color{green}{2} & \color{blue}{4} & \color{red}{6} \end{bmatrix} \$
OR:
\$ \begin{bmatrix} \color{red}{1} & \color{red}{2} & \color{red}{3} \\ \color{blue}{1} & \color{blue}{2} & \color{red}{4} \\ \color{green}{1} & \color{blue}{3} & \color{red}{5} \\ \color{green}{2} & \color{blue}{4} & \color{red}{6} \end{bmatrix} \$
Test cases
[[1,2,3,4,5], [1,2,3], [1]] => [[1,2,3], [1,2,4], [1,3,5]]
[[1,2,3,4,5,6], [1,2,3,4], [1,2]] => [[1,2,3], [1,2,4], [1,3,5], [2,4,6]]
OR [[1,2,3,4], [1,2,3,5], [1,2,4,6]]
[[6,8,9,6,5,8,2],[1,7,4,3,2],[2,3,1]] => [[6,8,9,6,5], [1,7,4,3,8], [2,3,1,2,2]]
OR [[6,8,9], [1,7,6], [2,4,5], [3,3,8], [1,2,2]]
[] => []
Rules
- You may use any standard I/O method
- Standard loopholes are forbidden
- This is code-golf, so the shortest code in bytes wins
✝ The name J-bracket was robbed from this question.