static IEnumerable TestGeneralDFS() { var result = new List<string>(); var dfs = new GeneralDFS<Node>(); dfs.Init(Root, Node.GetChildren, (context, branch) => result.Add(Node.BranchToString(branch))); dfs.Run(); return result; }
static IEnumerable TestGeneralDFS() { var result = new List <string>(); var dfs = new GeneralDFS <Node>(); dfs.Init(Root, Node.GetChildren, (context, branch) => result.Add(Node.BranchToString(branch))); dfs.Run(); return(result); }
public void TestGeneralDFSDepth() { var result = new List<string>(); var dfs = new GeneralDFS<Node>(); dfs.Init(null, Node.GetChildren, (context, branch) => result.Add(Node.BranchToString(branch)), 2); dfs.Run(); Assert.AreEqual(0, result.Count); dfs.Init(Root, Node.GetChildren, (context, branch) => result.Add(Node.BranchToString(branch)), 2); dfs.Run(); Assert.AreEqual(Paths2.Count, result.Count); for (int i = 0; i < result.Count; i++) { Assert.AreEqual(Paths2[i], result[i]); } }
public void TestGeneralDFSDepth() { var result = new List <string>(); var dfs = new GeneralDFS <Node>(); dfs.Init(null, Node.GetChildren, (context, branch) => result.Add(Node.BranchToString(branch)), 2); dfs.Run(); Assert.AreEqual(0, result.Count); dfs.Init(Root, Node.GetChildren, (context, branch) => result.Add(Node.BranchToString(branch)), 2); dfs.Run(); Assert.AreEqual(Paths2.Count, result.Count); for (int i = 0; i < result.Count; i++) { Assert.AreEqual(Paths2[i], result[i]); } }
public static void Main(string[] args) { var wordDict = LoadDictionary(DictionaryFileName); var allowedWords = new SortedSet <string> (); foreach (var w in wordDict) { if (w.Length == MaxAttributes) { allowedWords.Add(w); } } int total = 0; var found = new SortedSet <string> (); var dfs = new GeneralDFS <AttributeVariant> (); dfs.Init(null, GetNextAttributeVariants, (context, result) => { total++; var word = ""; var sb = new StringBuilder(); foreach (var node in result) { word += AttributeValues [node.AttributeIndex] [node.ValueIndex] [0]; if (sb.Length > 0) { sb.Append("-"); } sb.Append(AttributeValues [node.AttributeIndex] [node.ValueIndex].Substring(0, 3)); } word = word.ToLower(); if (allowedWords.Contains(word) && !found.Contains(word)) { found.Add(word); Console.WriteLine(word + " " + sb.ToString()); } }, MaxAttributes); dfs.Run(); Console.WriteLine("Total: " + total); Console.WriteLine("Found: " + found.Count); }
public static void Main(string[] args) { var wordDict = LoadDictionary(DictionaryFileName); var allowedWords = new SortedSet<string> (); foreach (var w in wordDict) { if (w.Length == MaxAttributes) allowedWords.Add(w); } int total = 0; var found = new SortedSet<string> (); var dfs = new GeneralDFS<AttributeVariant> (); dfs.Init(null, GetNextAttributeVariants, (context, result) => { total++; var word = ""; var sb = new StringBuilder (); foreach (var node in result) { word += AttributeValues [node.AttributeIndex] [node.ValueIndex] [0]; if (sb.Length > 0) sb.Append ("-"); sb.Append (AttributeValues [node.AttributeIndex] [node.ValueIndex].Substring (0, 3)); } word = word.ToLower (); if (allowedWords.Contains (word) && !found.Contains (word)) { found.Add (word); Console.WriteLine (word + " " + sb.ToString ()); } }, MaxAttributes); dfs.Run(); Console.WriteLine("Total: " + total); Console.WriteLine("Found: " + found.Count); }