コード例 #1
0
ファイル: Test.cs プロジェクト: pavor84/brute-force-solver
        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]);
            }
        }
コード例 #2
0
ファイル: Test.cs プロジェクト: pavor84/brute-force-solver
        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]);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: pavor84/brute-force-solver
 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;
 }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: pavor84/brute-force-solver
        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);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: pavor84/brute-force-solver
        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);
        }