using System;
using System.Collections.Generic;
using System.Linq;
public class Test
{
public static void Main()
{
List<string> validatedStrings = new List<string>();
List<string> subjectStrings = new List<string>()
{
"con", "cot", "eon", "net", "not", "one", "ten", "toe", "ton",
"cent", "cone", "conn", "cote", "neon", "none", "note", "once", "tone",
"cento", "conte", "nonce", "nonet", "oncet", "tenon", "tonne",
"nocent","concent", "connect"
}; //got a more longer wordlist
string startswithString = "co";
string endswithString = "et";
var sw =getCombinations(startswithString);
var ew = getCombinations(endswithString);
validatedStrings = subjectStrings.Where(z=>
sw.Any(x=>z.StartsWith(x) &&
!ew.Any(y=>z.EndsWith(y))))
.ToList();
foreach(var a in validatedStrings)
{
Console.WriteLine(a);
}
Console.WriteLine("\nDone");
}
static List<string> getCombinations(string s)
{
//Code that calculates combinations
return Permutations.Permutate(s);
}
}
public class Permutations
{
private static List<List<string>> allCombinations;
private static void CalculateCombinations(string word, List<string> temp)
{
if (temp.Count == word.Length)
{
List<string> clone = temp.ToList();
if (clone.Distinct().Count() == clone.Count)
{
allCombinations.Add(clone);
}
return;
}
for (int i = 0; i < word.Length; i++)
{
temp.Add(word[i].ToString());
CalculateCombinations(word, temp);
temp.RemoveAt(temp.Count - 1);
}
}
public static List<string> Permutate(string str)
{
allCombinations = new List<List<string>>();
CalculateCombinations(str, new List<string>());
List<string> combinations = new List<string>();
foreach(var a in allCombinations)
{
string c = "";
foreach(var b in a)
{
c+=b;
}
combinations.Add(c);
}
return combinations;
}
}
dXNpbmcgU3lzdGVtOwogICAgICAgIHVzaW5nIFN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljOwogICAgICAgIHVzaW5nIFN5c3RlbS5MaW5xOwoKICAgICAgICBwdWJsaWMgY2xhc3MgVGVzdAogICAgICAgIHsKICAgICAgICAgICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgTGlzdDxzdHJpbmc+IHZhbGlkYXRlZFN0cmluZ3MgPSBuZXcgTGlzdDxzdHJpbmc+KCk7CiAgICAgICAgICAgICAgICAgICAgICAgIExpc3Q8c3RyaW5nPiBzdWJqZWN0U3RyaW5ncyA9IG5ldyBMaXN0PHN0cmluZz4oKQogICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgImNvbiIsICJjb3QiLCAiZW9uIiwgIm5ldCIsICJub3QiLCAib25lIiwgInRlbiIsICJ0b2UiLCAidG9uIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICJjZW50IiwgImNvbmUiLCAiY29ubiIsICJjb3RlIiwgIm5lb24iLCAibm9uZSIsICJub3RlIiwgIm9uY2UiLCAidG9uZSIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiY2VudG8iLCAiY29udGUiLCAibm9uY2UiLCAibm9uZXQiLCAib25jZXQiLCAidGVub24iLCAidG9ubmUiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIm5vY2VudCIsImNvbmNlbnQiLCAiY29ubmVjdCIKICAgICAgICAgICAgICAgICAgICAgICAgfTsgLy9nb3QgYSBtb3JlIGxvbmdlciB3b3JkbGlzdAogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgIHN0cmluZyBzdGFydHN3aXRoU3RyaW5nID0gImNvIjsKICAgICAgICAgICAgICAgICAgICAgICAgc3RyaW5nIGVuZHN3aXRoU3RyaW5nID0gImV0IjsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgIHZhciBzdyA9Z2V0Q29tYmluYXRpb25zKHN0YXJ0c3dpdGhTdHJpbmcpOwoJCQkJCQl2YXIgZXcgPSBnZXRDb21iaW5hdGlvbnMoZW5kc3dpdGhTdHJpbmcpOwoKCgkJCQkJCSB2YWxpZGF0ZWRTdHJpbmdzID0gc3ViamVjdFN0cmluZ3MuV2hlcmUoej0+IAoJCQkJCSAgICBzdy5BbnkoeD0+ei5TdGFydHNXaXRoKHgpICYmIAoJCQkJCSAgICAgICAgIWV3LkFueSh5PT56LkVuZHNXaXRoKHkpKSkpCgkJCQkJICAgICAgICAuVG9MaXN0KCk7CiAgICAgICAgICAgICAgICAgICAgICAKCiAgICAgICAgICAgICAgICAgICAgICAgIGZvcmVhY2godmFyIGEgaW4gdmFsaWRhdGVkU3RyaW5ncykKICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKGEpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCJcbkRvbmUiKTsKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgIAogICAgICAgICAgICAgICAgc3RhdGljIExpc3Q8c3RyaW5nPiBnZXRDb21iaW5hdGlvbnMoc3RyaW5nIHMpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIC8vQ29kZSB0aGF0IGNhbGN1bGF0ZXMgY29tYmluYXRpb25zCiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBQZXJtdXRhdGlvbnMuUGVybXV0YXRlKHMpOwogICAgICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgcHVibGljIGNsYXNzIFBlcm11dGF0aW9ucwogICAgICAgIHsKICAgICAgICAgICAgICAgIHByaXZhdGUgc3RhdGljIExpc3Q8TGlzdDxzdHJpbmc+PiBhbGxDb21iaW5hdGlvbnM7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIHByaXZhdGUgc3RhdGljIHZvaWQgQ2FsY3VsYXRlQ29tYmluYXRpb25zKHN0cmluZyB3b3JkLCBMaXN0PHN0cmluZz4gdGVtcCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRlbXAuQ291bnQgPT0gd29yZC5MZW5ndGgpCiAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBMaXN0PHN0cmluZz4gY2xvbmUgPSB0ZW1wLlRvTGlzdCgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChjbG9uZS5EaXN0aW5jdCgpLkNvdW50KCkgPT0gY2xvbmUuQ291bnQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYWxsQ29tYmluYXRpb25zLkFkZChjbG9uZSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCB3b3JkLkxlbmd0aDsgaSsrKQogICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGVtcC5BZGQod29yZFtpXS5Ub1N0cmluZygpKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBDYWxjdWxhdGVDb21iaW5hdGlvbnMod29yZCwgdGVtcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGVtcC5SZW1vdmVBdCh0ZW1wLkNvdW50IC0gMSk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgcHVibGljIHN0YXRpYyBMaXN0PHN0cmluZz4gUGVybXV0YXRlKHN0cmluZyBzdHIpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGFsbENvbWJpbmF0aW9ucyA9IG5ldyBMaXN0PExpc3Q8c3RyaW5nPj4oKTsKICAgICAgICAgICAgICAgICAgICAgICAgQ2FsY3VsYXRlQ29tYmluYXRpb25zKHN0ciwgbmV3IExpc3Q8c3RyaW5nPigpKTsKICAgICAgICAgICAgICAgICAgICAgICAgTGlzdDxzdHJpbmc+IGNvbWJpbmF0aW9ucyA9IG5ldyBMaXN0PHN0cmluZz4oKTsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yZWFjaCh2YXIgYSBpbiBhbGxDb21iaW5hdGlvbnMpCiAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJpbmcgYyA9ICIiOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZvcmVhY2godmFyIGIgaW4gYSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjKz1iOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb21iaW5hdGlvbnMuQWRkKGMpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBjb21iaW5hdGlvbnM7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgfQ==