Adapted from this StackOverflow question
In this challenge you will take a list of lists of integers, e.g.
A = [[1,2],[3,4],[5],[]] And an additional single integer (e.g. n = 7). If you were to add n to the front of one of the lists in A there would be as many ways to do that as there are lists in A. In this example 4:
A' = [[7,1,2],[3,4],[5],[]] A' = [[1,2],[7,3,4],[5],[]] A' = [[1,2],[3,4],[7,5],[]] A' = [[1,2],[3,4],[5],[7]] In this challenge you will output all possible ways to do this, in the order of how early n is inserted. So for the example the output is just:
[ [[7,1,2],[3,4],[5],[]] , [[1,2],[7,3,4],[5],[]] , [[1,2],[3,4],[7,5],[]] , [[1,2],[3,4],[5],[7]] ] This is codegolf so answer answers will be scored in bytes with fewer bytes being better.
Test cases
9, [] -> [] 9, [[]] -> [[[9]]] 10, [[1,2,3]] -> [[[10,1,2,3]]] 7, [[1,2],[3,4],[5],[]] -> [[[7,1,2],[3,4],[5],[]],[[1,2],[7,3,4],[5],[]],[[1,2],[3,4],[7,5],[]],[[1,2],[3,4],[5],[7]]] 2, [[1,2],[2,2],[2]] -> [[[2,1,2],[2,2],[2]],[[1,2],[2,2,2],[2]],[[1,2],[2,2],[2,2]]]