示例#1
0
 // Para probar tus ideas desde la consola
 public static void InteractiveTest(LocateTheTimeStone g)
 {
     Console.WriteLine("Prueba interactiva con {0} piedras y {1} intentos",
                       g.NumStones, g.MaxNumComparisons);
     Console.WriteLine("Escriba uno de los siguientes comandos:");
     Console.WriteLine("C <L1> <R1> <L2> <R2>");
     Console.WriteLine("E <pos>");
     Console.WriteLine("* El comando C compara el peso del intervalo L1 a R1");
     Console.WriteLine("  contra el intervalo L2 a R2");
     Console.WriteLine("* El comando E termina la prueba y sometes la posicion");
     Console.WriteLine("  pos como tu respuesta final");
     while (true)
     {
         Console.Write("[{0}/{1}] > ", g.CurNumComparisons, g.MaxNumComparisons);
         string line = Console.ReadLine();
         if (line == null)
         {
             break;
         }
         if (line.Length == 0)
         {
             continue;
         }
         string[] parts = line.Split(' ');
         if (parts.Length == 0)
         {
             continue;
         }
         if (parts[0] == "C")
         {
             if (parts.Length != 5)
             {
                 Console.WriteLine("Comando acepta cuatro parametros");
                 continue;
             }
             int L1 = int.Parse(parts[1]);
             int R1 = int.Parse(parts[2]);
             int L2 = int.Parse(parts[3]);
             int R2 = int.Parse(parts[4]);
             int resultadoComparacion = g.Compare(L1, R1, L2, R2);
             if (resultadoComparacion < 0)
             {
                 Console.WriteLine(
                     "Intervalo [{0} .. {1}] es mas liviano que intervalo [{2} .. {3}]",
                     L1, R1, L2, R2);
             }
             else if (resultadoComparacion > 0)
             {
                 Console.WriteLine(
                     "Intervalo [{0} .. {1}] es mas pesado que intervalo [{2} .. {3}]",
                     L1, R1, L2, R2);
             }
             else
             {
                 Console.WriteLine(
                     "Intervalo [{0} .. {1}] tiene el mismo peso que intervalo [{2} .. {3}]",
                     L1, R1, L2, R2);
             }
         }
         else if (parts[0] == "E")
         {
             if (parts.Length != 2)
             {
                 Console.WriteLine("Comando acepta un (solo) parametro");
                 continue;
             }
             int answer = int.Parse(parts[1]);
             try
             {
                 g.VerifyAnswer(answer);
                 Console.WriteLine("Felicidades! Tu respuesta es correcta");
             }
             catch (Exception e)
             {
                 Console.WriteLine(e.Message);
             }
             break;
         }
         else
         {
             Console.WriteLine("Comando invalido");
             continue;
         }
     }
 }
示例#2
0
    public static void Main()
    {
        // ===========================================================
        // Test 0 o negativo: entre 2 a 100 piedras, 100 comparaciones
        // ===========================================================

        /*
         * {
         *  LocateTheTimeStone g = new LocateTheTimeStone(0);
         *  InteractiveTest(g);
         * }
         */


        // ===========================================================
        // Test 1: 10 piedras, 100 comparaciones
        // ===========================================================
        {
            Solution           s = new BruteForceSolution();
            LocateTheTimeStone g = new LocateTheTimeStone(1);
            int answer           = s.Solve(g);
            g.VerifyAnswer(answer);
            Console.WriteLine(
                "Test {0}  OK  #Comparisons: {1} of {2}",
                1, g.CurNumComparisons, g.MaxNumComparisons);
        }


        // ===========================================================
        // Test 2: 10 piedras, todas falsas, 100 comparaciones
        // ===========================================================
        {
            Solution           s = new BruteForceSolution();
            LocateTheTimeStone g = new LocateTheTimeStone(1);
            int answer           = s.Solve(g);
            g.VerifyAnswer(answer);
            Console.WriteLine(
                "Test {0}  OK  #Comparisons: {1} of {2}",
                2, g.CurNumComparisons, g.MaxNumComparisons);
        }


        // ===========================================================
        // Tests 3-100: 1000 piedras, 1000 comparaciones
        // ===========================================================
        for (int testNum = 3; testNum <= 100; testNum++)
        {
            Solution           s = new YourSolution();
            LocateTheTimeStone g = new LocateTheTimeStone(testNum);
            int answer           = s.Solve(g);
            g.VerifyAnswer(answer);
            Console.WriteLine(
                "Test {0}  OK  #Comparisons: {1} of {2}",
                testNum, g.CurNumComparisons, g.MaxNumComparisons);
        }


        // ===========================================================
        // Tests 101-200: 1000 piedras, 501 comparaciones
        // ===========================================================
        for (int testNum = 101; testNum <= 200; testNum++)
        {
            Solution           s = new YourSolution();
            LocateTheTimeStone g = new LocateTheTimeStone(testNum);
            int answer           = s.Solve(g);
            g.VerifyAnswer(answer);
            Console.WriteLine(
                "Test {0}  OK  #Comparisons: {1} of {2}",
                testNum, g.CurNumComparisons, g.MaxNumComparisons);
        }


        // ===========================================================
        // Tests 201-300: 10000 piedras, 15 comparaciones
        // ===========================================================
        for (int testNum = 201; testNum <= 300; testNum++)
        {
            Solution           s = new YourSolution();
            LocateTheTimeStone g = new LocateTheTimeStone(testNum);
            int answer           = s.Solve(g);
            g.VerifyAnswer(answer);
            Console.WriteLine(
                "Test {0}  OK  #Comparisons: {1} of {2}",
                testNum, g.CurNumComparisons, g.MaxNumComparisons);
        }


        // ===========================================================
        // Tests 301-400: 100000 piedras, 15 comparaciones
        // ===========================================================

        for (int testNum = 301; testNum <= 400; testNum++)
        {
            Solution           s = new YourSolution();
            LocateTheTimeStone g = new LocateTheTimeStone(testNum);
            int answer           = s.Solve(g);
            g.VerifyAnswer(answer);
            Console.WriteLine(
                "Test {0}  OK  #Comparisons: {1} of {2}",
                testNum, g.CurNumComparisons, g.MaxNumComparisons);
        }


        // ===========================================================
        // Tests 401-500: 1000000 piedras, 15 comparaciones
        // ===========================================================

        for (int testNum = 401; testNum <= 500; testNum++)
        {
            Solution           s = new YourSolution();
            LocateTheTimeStone g = new LocateTheTimeStone(testNum);
            int answer           = s.Solve(g);
            g.VerifyAnswer(answer);
            Console.WriteLine(
                "Test {0}  OK  #Comparisons: {1} of {2}",
                testNum, g.CurNumComparisons, g.MaxNumComparisons);
        }



        // ===========================================================
        // Tests 401-500: 10000000 piedras, 17 comparaciones
        // ===========================================================

        for (int testNum = 501; testNum <= 600; testNum++)
        {
            Solution           s = new YourSolution();
            LocateTheTimeStone g = new LocateTheTimeStone(testNum);
            int answer           = s.Solve(g);
            g.VerifyAnswer(answer);
            Console.WriteLine(
                "Test {0}  OK  #Comparisons: {1} of {2}",
                testNum, g.CurNumComparisons, g.MaxNumComparisons);
        }
    }