Exemplo n.º 1
0
        private static void RunAnagram(WrappingWriter writer, List <string> words, List <string> wordTest, IMediator mediator)
        {
            Stopwatch stopwatch = new Stopwatch();
            Anagram   anagram   = new Anagram(writer, mediator);
            GenericCombinator <char> combinations = new GenericCombinator <char>();

            writer.WriteLine($"{Environment.NewLine}Running Anagram");
            stopwatch.Start();
            foreach (var word in wordTest)
            {
                writer.Write($"{word}:");
                anagram.FindAll(word);
                writer.WriteLine();
            }
            stopwatch.Stop();
            writer.WriteLine($"{Environment.NewLine}Done in {stopwatch.ElapsedMilliseconds}ms!");
        }
Exemplo n.º 2
0
        private static void RunAnagram2A(WrappingWriter writer, List <string> words, List <string> wordTest)
        {
            Stopwatch          stopwatch  = new Stopwatch();
            ICombinator <char> combinator = new GenericCombinator <char>();
            Anagram2           anagram    = new Anagram2(combinator, words);

            writer.WriteLine($"{Environment.NewLine}Running Anagram2A");
            stopwatch.Start();
            foreach (var word in wordTest)
            {
                writer.Write($"{word}:");
                var results = anagram.FindAll(word);
                foreach (var result in results)
                {
                    writer.Write($@" {result}");
                }
                writer.WriteLine();
            }
            stopwatch.Stop();
            writer.WriteLine($"{Environment.NewLine}Done in {stopwatch.ElapsedMilliseconds}ms!");
        }
Exemplo n.º 3
0
        private static void RunCombinator(WrappingWriter writer, List <string> wordTest, IMediator mediator)
        {
            Stopwatch stopwatch = new Stopwatch();
            GenericCombinator <char> combinations = new GenericCombinator <char>();

            writer.WriteLine($"{Environment.NewLine}Running Combinator");
            stopwatch.Start();
            foreach (var word in wordTest)
            {
                writer.Write($"{word}:");
                var combos = combinations.FindCombinations(word.ToCharArray());
                foreach (var combo in combos)
                {
                    mediator.Publish(new ComboFound {
                        Combo = new string(combo)
                    }).Wait();
                }
                writer.WriteLine();
            }
            stopwatch.Stop();
            writer.WriteLine($"{Environment.NewLine}Done in {stopwatch.ElapsedMilliseconds}ms!");
        }
Exemplo n.º 4
0
        static void Main()
        {
            List <string> words;
            List <string> wordTest = new List <string>
            {
                "ABC",
                "paste",
                "kinship",
                "kinships",
                "enlist",
                "boaster",
                "fresher",
                "sinks",
                "knits",
                "rots",
                "crepitus",
                "punctilio",
                "sunders",
                "MA's",
                "epee",
                "aardvark"
            };

            words = LoadWords().Result;
            var writer   = new WrappingWriter(Console.Out);
            var mediator = BuildMediator(writer, words);

            RunAnagrammer(writer, words, wordTest);

            //RunCombinator(writer, words, wordTest, mediator);

            //RunAnagram(writer, words, wordTest, mediator);

            //RunAnagram2A(writer, words, wordTest);
            RunAnagram2B(writer, words, wordTest);

            Console.ReadKey();
        }
Exemplo n.º 5
0
        private static void RunAnagrammer(WrappingWriter writer, List <string> words, List <string> wordTest)
        {
            Stopwatch  swSearch   = new Stopwatch();
            Stopwatch  swElapsed  = new Stopwatch();
            Anagrammer anagrammer = new Anagrammer(words);

            writer.WriteLine($"{Environment.NewLine}Starting Anagrammer");

            swElapsed.Start();
            swSearch.Start();
            var resultSort = anagrammer.FindAll(wordTest);

            swSearch.Stop();

            resultSort.ForEach(g => writer.WriteLine(String.Join(" ", g)));
            swElapsed.Stop();


            writer.WriteLine($"{Environment.NewLine}Anagram2B completed! {Environment.NewLine}\tSearchTime:   {swSearch.Elapsed}{Environment.NewLine}\tElapsed Time: {swElapsed.Elapsed}");
            writer.WriteLine($"Number of words: {words.Count}");
            writer.WriteLine($"Number of words to test: {wordTest.Count}");
            writer.WriteLine($"Number of anagram pairs: {resultSort.Count}");
        }
Exemplo n.º 6
0
 public Anagram(WrappingWriter writer, IMediator mediator)
 {
     _writer   = writer;
     _mediator = mediator;
 }