The word BARK was made up using blocks as follows:
Solutions
For the possible solutions blow, each time I ran the console application I got a different result in terms of elapsed time. I guess an average of a few runs would be the best to have an unbiased result but the below paints a pretty clear picture (for me anyway) that the action deligate is the fastest.
1 2 3 4 5 6 7 8 9 10 11
ForeachLoop: 00:00:00.0056731 ActionDelegate: 00:00:00.0015526 < fastest run and solution Regex: 00:00:00.0122734
publicboolMakeWord(string word, List<string> blocks) { var blocksLeft = new List<string>(blocks); var stringComparison = StringComparison.CurrentCultureIgnoreCase;
foreach (var letter in word) { if (!blocksLeft.Any(b => b.Contains(letter, stringComparison))) returnfalse;
publicboolMakeWord2(string word, List<string> blocks) { var letters = word.ToList(); var blocksLeft = new List<string>(blocks); var stringComparison = StringComparison.CurrentCultureIgnoreCase;
letters.ForEach(letter => {
if (!blocksLeft.Any(b => b.Contains(letter, stringComparison))) return;