R
R
rundll322022-03-13 20:48:16
Algorithms
rundll32, 2022-03-13 20:48:16

Loop through all combinations of arrays of strings?

As input, the program can receive a different number of arrays, the number of which is not known before the program is executed. And all variations of strings from these arrays must be used.
If the data were static, I would write nested arrays, but without them I don’t understand what to do, but I can’t figure out how to make it recursive.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2022-03-13
@wataru

The recursive function must take the current set of rows and the number of the next array. The function loops through a string from the next array, adds that string to the current set, and is called recursively. After the call, the last line must be removed from the current set. If at the beginning of the function you see that all arrays have already been processed, output the current set as a response and return from the function.
Also, of course, you need to pass an array of arrays of strings to the function - your initial data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question