There is such a data set:
var replies1 = new List<int>() { 1, 4, 7 }; var replies2 = new List<int>() { 2, 5, 8 }; var replies3 = new List<int>() { 3, 6, 9 }; There is an array of arrays, these arrays are aggregated:
var mas = new List<List<int>>() { replies1, replies2, replies3 }; It is necessary to build all possible routes. The routes will be as follows:
123 423 723 156 456 756 ... The number of arrays can be unlimited, as well as their length. In essence, it is a tree with many vertices. Can you please tell us how you can implement an algorithm that collects all possible routes? Obviously, you can implement recursively, but my vain attempts have come to nothing.
Solution with a fixed number of arrays:
for (int i = 0; i < replies1.Count; i++) { for (int j = 0; j < replies2.Count; j++) { for (int k = 0; k < replies3.Count; k++) { Console.Write(String.Format("{0}, {1}, {2}", replies1[i], replies2[j], replies3[k])); Console.WriteLine(); } } }
1or1-2-3-6-9-8-5-4-7? What are the directions of the routes? Will route7-8-9and9-8-7be considered the same? If you want to bypass trees, make trees from your matrix. - Jagailo