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";
foreach(var z in subjectStrings)
{
bool valid = false;
foreach(var a in getCombinations(startswithString))
{
foreach(var b in getCombinations(endswithString))
{
if(z.StartsWith(a) && !z.EndsWith(b))
{
valid = true;
break;
}
}
if(valid)
{
break;
}
}
if(valid)
{
validatedStrings.Add(z);
}
}
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+KCk7CiAgICAgICAgICAgICAgICAgICAgICAgIExpc3Q8c3RyaW5nPiBzdWJqZWN0U3RyaW5ncyA9IG5ldyBMaXN0PHN0cmluZz4oKQogICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgImNvbiIsICJjb3QiLCAiZW9uIiwgIm5ldCIsICJub3QiLCAib25lIiwgInRlbiIsICJ0b2UiLCAidG9uIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICJjZW50IiwgImNvbmUiLCAiY29ubiIsICJjb3RlIiwgIm5lb24iLCAibm9uZSIsICJub3RlIiwgIm9uY2UiLCAidG9uZSIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiY2VudG8iLCAiY29udGUiLCAibm9uY2UiLCAibm9uZXQiLCAib25jZXQiLCAidGVub24iLCAidG9ubmUiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIm5vY2VudCIsImNvbmNlbnQiLCAiY29ubmVjdCIKICAgICAgICAgICAgICAgICAgICAgICAgfTsgLy9nb3QgYSBtb3JlIGxvbmdlciB3b3JkbGlzdAogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgIHN0cmluZyBzdGFydHN3aXRoU3RyaW5nID0gImNvIjsKICAgICAgICAgICAgICAgICAgICAgICAgc3RyaW5nIGVuZHN3aXRoU3RyaW5nID0gImV0IjsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICBmb3JlYWNoKHZhciB6IGluIHN1YmplY3RTdHJpbmdzKQogICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBib29sIHZhbGlkID0gZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3JlYWNoKHZhciBhIGluIGdldENvbWJpbmF0aW9ucyhzdGFydHN3aXRoU3RyaW5nKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3JlYWNoKHZhciBiIGluIGdldENvbWJpbmF0aW9ucyhlbmRzd2l0aFN0cmluZykpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZih6LlN0YXJ0c1dpdGgoYSkgJiYgIXouRW5kc1dpdGgoYikpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YWxpZCA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYodmFsaWQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZih2YWxpZCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YWxpZGF0ZWRTdHJpbmdzLkFkZCh6KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICAgICAgZm9yZWFjaCh2YXIgYSBpbiB2YWxpZGF0ZWRTdHJpbmdzKQogICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoYSk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIlxuRG9uZSIpOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBzdGF0aWMgTGlzdDxzdHJpbmc+IGdldENvbWJpbmF0aW9ucyhzdHJpbmcgcykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgLy9Db2RlIHRoYXQgY2FsY3VsYXRlcyBjb21iaW5hdGlvbnMKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIFBlcm11dGF0aW9ucy5QZXJtdXRhdGUocyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBwdWJsaWMgY2xhc3MgUGVybXV0YXRpb25zCiAgICAgICAgewogICAgICAgICAgICAgICAgcHJpdmF0ZSBzdGF0aWMgTGlzdDxMaXN0PHN0cmluZz4+IGFsbENvbWJpbmF0aW9uczsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgcHJpdmF0ZSBzdGF0aWMgdm9pZCBDYWxjdWxhdGVDb21iaW5hdGlvbnMoc3RyaW5nIHdvcmQsIExpc3Q8c3RyaW5nPiB0ZW1wKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAodGVtcC5Db3VudCA9PSB3b3JkLkxlbmd0aCkKICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIExpc3Q8c3RyaW5nPiBjbG9uZSA9IHRlbXAuVG9MaXN0KCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNsb25lLkRpc3RpbmN0KCkuQ291bnQoKSA9PSBjbG9uZS5Db3VudCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbGxDb21iaW5hdGlvbnMuQWRkKGNsb25lKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IHdvcmQuTGVuZ3RoOyBpKyspCiAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0ZW1wLkFkZCh3b3JkW2ldLlRvU3RyaW5nKCkpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIENhbGN1bGF0ZUNvbWJpbmF0aW9ucyh3b3JkLCB0ZW1wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0ZW1wLlJlbW92ZUF0KHRlbXAuQ291bnQgLSAxKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBwdWJsaWMgc3RhdGljIExpc3Q8c3RyaW5nPiBQZXJtdXRhdGUoc3RyaW5nIHN0cikKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgYWxsQ29tYmluYXRpb25zID0gbmV3IExpc3Q8TGlzdDxzdHJpbmc+PigpOwogICAgICAgICAgICAgICAgICAgICAgICBDYWxjdWxhdGVDb21iaW5hdGlvbnMoc3RyLCBuZXcgTGlzdDxzdHJpbmc+KCkpOwogICAgICAgICAgICAgICAgICAgICAgICBMaXN0PHN0cmluZz4gY29tYmluYXRpb25zID0gbmV3IExpc3Q8c3RyaW5nPigpOwogICAgICAgICAgICAgICAgICAgICAgICBmb3JlYWNoKHZhciBhIGluIGFsbENvbWJpbmF0aW9ucykKICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cmluZyBjID0gIiI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yZWFjaCh2YXIgYiBpbiBhKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGMrPWI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbWJpbmF0aW9ucy5BZGQoYyk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGNvbWJpbmF0aW9uczsKICAgICAgICAgICAgICAgIH0KICAgICAgICB9