Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string magicPhrase = Console.ReadLine();

            Console.WriteLine(Bilbo.Optimize(magicPhrase));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Start();
            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            string result = "";
            int    total  = 0;
            bool   ok     = true;

            for (int i = 0; i < TestCases.Length; i++)
            {
                //
                stopWatch.Reset();
                stopWatch.Start();
                //
                string program = Bilbo.Optimize(TestCases[i]);
                //
                stopWatch.Stop();
                //
                string item = "";
                item += TestCases[i] + NewLine + program + NewLine;
                //
                Turing turing = new Turing();
                turing.Execute(program);
                string output  = turing.GetOutput();
                bool   correct = output.Equals(TestCases[i]);
                if (correct)
                {
                    //
                    item += new Turing().ExecuteLetters(program) + NewLine;
                    item += program.Length + " ";
                    if (program.Length > BestCases[i].Length)
                    {
                        item += "***Suboptimal*** ";
                    }
                    if (program.Length < BestCases[i].Length)
                    {
                        item += "***New Best Case*** ";
                    }
                    total += program.Length;
                }
                else
                {
                    item += "PROBLEM ";
                    ok    = false;
                }
                //
                Turing t2 = new Turing();
                t2.Execute(BestCases[i]);
                if (!t2.GetOutput().Equals(TestCases[i]))
                {
                    throw new Exception("Best case is wrong.");
                }
                //
                long time = stopWatch.ElapsedMilliseconds;
                item += time + "ms -- " + Bilbo.PatternDebug;
                //
                item   += NewLine + NewLine;
                result += item;
            }

            logResult(result, total, ok);
        }