Beginners Advent Challenge #6
Santa first ponders the challenge. In Santas opinion should be the formula
the right one. Where n is the number of reindeers. With nine reindeers would be 27 combinations possible.
At first Santa develop two approaches in C# to find out what possible solutions there are.
//-Begin----------------------------------------------------------------
using System;
public class Test {
public static void Main() {
//-Array approach---------------------------------------------------
int i = 1;
string[] Formers = { "Emily", "Ed", "Eryk" };
string[] Loyals = { "Lucas", "Lili", "Lars" };
string[] Rookies = { "Rebecca", "Robert", "Ricky" };
foreach(string Former in Formers) {
foreach(string Loyal in Loyals) {
foreach(string Rookie in Rookies) {
Console.WriteLine("Team" + i.ToString() + ": "
+ Former + ", " + Loyal + ", " + Rookie);
i += 1;
}
}
}
//-Jagged Array approach--------------------------------------------
i = 1;
string[][] Reindeers = {
new string[] { "Emily", "Ed", "Eryk" },
new string[] { "Lucas", "Lili", "Lars" },
new string[] { "Rebecca", "Robert", "Ricky" }
};
for(int j= 0; j < Reindeers[0].Length; j++) {
for(int k = 0; k < Reindeers[1].Length; k++) {
for(int l = 0; l < Reindeers[2].Length; l++) {
Console.WriteLine("Team" + i.ToString() + ": "
+ Reindeers[0][j] + ", " + Reindeers[1][k] + ", "
+ Reindeers[2][l]);
i += 1;
}
}
}
}
}
//-End------------------------------------------------------------------
In the first approach Santa uses three arrays with the names of the reindeers an loops over this array in a triple nested loop. Not elegant, but it works. In the second approach Santa uses an jagged array of strings. Last but not least Santa builds also a working solution, but the complexity is not less and Santa perceives the code as more incomprehensible. Santa decides to implement the first approach as Invoke Code activity.
Main_InvokeCode.xaml (4.7 KB)
No surprise, everything works as expected.
In this context, Santa finds it interesting that it is quite easy to convert the code into a workflow representation.
Main_Workflow.xaml (9.8 KB)
Santa is curious to see if his assumptions are correct and meanwhile he will think about expansion possibilities of his solution.