I have a Map<Integer, List<Float>> that represent a position with some scores, and I would like to generate all possible combinations of scores per position (essentially the cross-product of each list from the original map) into a List<List<Float>>. So let’s say I have the following map:
{ 1 => [0.1f, 0.2f], 2 => [0.3f, 0.4f] }
I would to get the following list of lists of floats:
[[0.1f, 0.3f], [0.1f, 0.4f], [0.2f, 0.3f], [0.2f, 0.4f]]
I am pretty sure I have to use recursion, just not sure how to go on about it..
any time you have a recursive algorithm to code, you need an inductive definition to help design it.
base case: {} ↦ []
inductive step: M ↦ L ⇒ ( M ∪ { n ↦ S } ) ↦ L × S
For each element in S, you add it to the end of every list in L, and add the resulting list to your output.
It should be pretty easy from here, and then you can make it non-recursive and reduce some of the copying going on.