<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Matemática Virtual, Ing.MSc. Fernando Carrillo & Ing.MSc. Cecilia Izurieta</title>
     <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
     <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.9.2/html2pdf.bundle.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML"></script>
</head>
<body>
    <?php include 'encabezado.php'; ?>
    <main>
        <?php include 'menui.php'; ?>
        <div class="container mt-5 overflow-auto">
            <!-- Botón de descarga -->
            
            <div class="list-group">

                <?php
$ejercicio=0;
            for ($i = 1; $i <= 20; $i++) {
                
                echo '<div class="card mb-3">';
                   
                    
               $ep = rand(2,3);
               $n1 = rand(4,10); 
               $n2 = rand(4,10);
               $n3 = rand(4,10);
               $n4 = rand(4,10);
               $n5 = rand(4,10);
               $n6 = rand(4,10);
               
               $n6c = pow($n6,0);
               $n7 = rand(4,10);
               $n8 = rand(4,10);
               $n9 = rand(4,10);
               $ex1 = rand(2,4);
               $ex2 = rand(5,6);
               $ex3 = rand(7,8);
               $ex4 = rand(2,4);
               $ex5 = rand(5,6);
               $ex6 = rand(7,8);
               $ex7 = rand(2,4);
               $ex8 = rand(5,6);
               $ex9 = rand(7,8);
               $ex10 = rand(2,4);
               

               


               
               $a = ['a', 'b', 'x^2yb', 'xy^2c'];
               $b = ['x', 'y', 'x^2yb', 'xy^2c'];
               $c = ['m', 'n', 'm^2ab', 'ny^2b'];
               $d = ['ab', 'xy', 'x^2y', 'xy^2'];
               $e = ['cd', 'mn', 'm^2y', 'xn^2'];
               $f = ['axy', 'xyb', 'x^2yb', 'xy^2c'];
                $a1 = $a[array_rand($a)];
                 $b1 = $b[array_rand($b)];
                  $c1 = $c[array_rand($c)];
                $d1 = $a[array_rand($d)];
                 $e1 = $a[array_rand($e)];
                  $f1 = $a[array_rand($f)];
$ejercicio = $ejercicio+1
//$ejercicio=3;
?>
          
            <h5 class="card-title">Ejercicio <?php echo $i; ?></h5>
              <?php
              switch($ejercicio) {


                case 1:
                  echo "<p class='card-text'> \($n1^$ex1 \\times $n1^$ex3 \\times $n1^{-$ex2}  \)</p>";
                  
                  break;
                case 2:
                  echo "<p class='card-text'> \($n2^{-$ex4} \div $n2^$ex5 \\times $n2^{-$ex6}\\times $n2^{$ex7}  \)</p>";
                  break;
                case 3:
                  echo "<p class='card-text'> \(($n3^{-$ex9} \div $n3^{$ex10})^$ex9 \\times $n3^{-$ex1}\\times $n3^{$ex2}  \)</p>";
                  break;
                case 4:
                  echo "<p class='card-text'> \((($n4^{-$ex9} \div $n4^{$ex10})^$ex9 \\times $n4^{-$ex1})^$ex4\\times $n4^{$ex2}  \)</p>";
                  break;
                case 5:
                  echo "<p class='card-text'> \\($n5^$ex2 \\times $n5^{-$ex4} \\times ((($n5^{-$ex6} \\times $n5^$ex7 \\times $n5^$ex8 \\times $n5^{-$ex9})^$ex1)^(-$ex5))^$ex1  \\)</p> ";
                  break;
                   case 6:
                echo "<p class='card-text'> \( $n6^$ex1 \div $n6^$ex3 \\times $n6^{-$ex2} \div $n6^$ex4 \\times $n6^{-$ex6}   \\times $n6^$ex5 \\times $n6^{-$ex1}   \\times $n6^$ex1 \\times $n6^{-$ex2}   \div $n6^$ex2 \div $n6^{-$ex5}    \)</p>";
                    break;
                
                case 7:
                echo "<p class='card-text'> \( $n7^$ex1 \\times $n7^$ex3 \\times $n7^{-$ex2} \\times $n7^$ex4 \\times $n7^{-$ex6}   \\times $n7^$ex5 \\times $n7^{-$ex1}   \\times $n7^$ex1 \\times $n7^{-$ex2}   \\times $n7^$ex2 \\times $n7^{-$ex5}    \)</p>";
                break;
                case 8:
               echo "<p class='card-text'> \( ((($n8^$ex1 \\times $n8^$ex3)^$ex1 \\times ($n8^{-$ex2} \\times $n8^$ex4) \\times( $n8^{-$ex6}   \\times $n8^$ex5)^$ex2)^$ex7 \\times ($n8^{-$ex1}   \\times $n8^$ex1)^$ex3 \\times ($n8^{-$ex2}   \\times $n8^$ex2)^{-$ex4})^$ex2 \\times $n8^{-$ex5}    \)</p>";
                break;
                case 9:
                echo "<p class='card-text'> \(  \\frac{ $n1^$ex1 \\times $n1^$ex3 \\times $n1^{-$ex2}}{ $n1^$ex4 \\times $n1^$ex5 \\times $n1^{-$ex6}} \)</p>"; 
                break;
                case 10:
                echo "<p class='card-text'> \( \\left(\\frac{ ($n2^$ex1 \\times $n2^$ex3)^$ex4 \\times $n2^{-$ex2}} { $n2^$ex4 \\times $n2^$ex5 \\times $n2^{-$ex6}}\\right)^{-1} \)</p>"; 
                break;
                case 11:
                echo "<p class='card-text'> \(  \\left(\\frac{ $n3^$ex1 \\times $n3^$ex3 \\times $n3^{-$ex2}}{ $n3^$ex1 \\times $n3^$ex2 \\times $n3^{-$ex4}}\\right)^$ex9 \\times \\frac{ ((($n3^$ex3)^$ex1)^{-$ex4} \\times $n3^$ex4)^$ex4 \\times $n3^{-$ex5}}{ $n3^$ex6 \\times $n3^$ex7 \\times $n3^{-$ex7}} \)</p>";
                break;
                case 12:
                echo "<p class='card-text'> \( {[($n5^$ex4 \\times $n5^$ex3)^{-8} \\times $n5^{-$ex1}]^$ex6}^$ex2 \\times ($n5^$ex2 \div $n5^{-$ex3}   \\times $n5^$ex4 \\times $n5^{-$ex5}   \div $n5^$ex5 \\times $n5^{-$ex6}   \div $n5^$ex7 \\times $n5^{-$ex8})^0    \)</p>";
                break;
                case 13:
                echo "<p class='card-text'> \( {[($n6^$ex4 \\times $n6^$ex3)^{-8} \div $n6^{-$ex1}]^$ex6} \\times ((($n6^$ex2 \div $n6^{-$ex3})^0)^1  \div $n6^$ex4 \\times $n6   \)</p>";
                break;
                case 14:
                $n6 = rand(4,6);
               $n6a = pow($n6,($ep));
               $n6b = pow($n6,($ep+1));
                echo "<p class='card-text'> \(  \\frac{($n6^$ex4 \\times $n6a^$ex3)^{-8}}{ $n6b^$ex4 \\times $n6} \\times \\frac{[($n6^$ex4 \\times $n6^$ex3)^{-8} \\times $n6c^{-$ex1}]^$ex6}{1} \)</p> ";
                break;
                case 15:
                $n6 = rand(2,4);
               $n6a = pow($n6,($ep));
               $n6b = pow($n6,($ep+1));
                echo "<p class='card-text'> \(  (\\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n3})^2 \\times \\frac{[($n6^$ex4 \\times $n6^$ex5)^{$ep} ]^$ex1}{$n6}   \)</p> ";
                
                break;
                case 16:
                $n6 = rand(2,4);
               $n6a = pow($n6,($ep));
               $n6b = pow($n6,($ep+1));
                echo "<p class='card-text'> \(  \\frac{ $n6a^$ex1}{ $n6b^$ex2 \div $n3} \div \\frac{[($n6^$ex4 \div $n6^$ex5)^{$ep} ]^$ex1}{$n6} \div $n6a^$ex1 \div $n3^0  \)</p> ";
                
                break;
                case 17:
                $n6 = rand(2,4);
               $n6a = pow($n6,($ep));
               $n6b = pow($n6,($ep+1));
                echo "<p class='card-text'> \(  \\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n3} \\times \\frac{[($n6^$ex4 \div $n6^$ex5)^{$ep} ]^$ex1}{$n6} \\times  \\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n3} \\times \\frac{[($n6^$ex4 )^{$ep} ]^$ex1}{$n6}  \)</p> ";
                
                break;
                case 18:
                $n6 = rand(2,4);
               $n6a = pow($n6,($ep));
               $n6b = pow($n6,($ep+1));
                echo "<p class='card-text'> \( \\frac{\\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n6} \\times (\\frac{[($n6^$ex4 \div $n6^$ex5)^{$ep} ]^$ex1}{$n6})^0  }{ $n6a^$ex2 \\times  \\frac{ $n6a^$ex3}{ $n6b^$ex2 \\times $n6a} } \)</p> ";
                
                break;
                case 19:
                $n6 = rand(2,4);
               $n6a = pow($n6,($ep));
               $n6b = pow($n6,($ep+1));
                echo "<p class='card-text'> \( \\frac{\\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n6} \\times (\\frac{[($n6^$ex4 \div $n6^$ex5)^{$ep} ]^$ex1}{$n6})^0  }{ $n6a^$ex2 \\times  \\frac{ $n6a^$ex3}{ $n6b^$ex2 \\times $n6a} \\times  \\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n3} \\times \\frac{[($n6^$ex4 )^{$ep} ]^$ex1}{$n6}} \div \\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n3} \\times \\frac{[($n6^$ex4 )^{$ep} ]^$ex1}{$n6}  \)</p> ";
                
                break;
                
                case 20:
                $n6 = rand(2,4);
               $n6a = pow($n6,($ep));
               $n6b = pow($n6,($ep+1));
                echo "<p class='card-text'> \( \\frac{\\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n6} \\times (\\frac{[($n6^$ex4 \div $n6^$ex5)^{$ep} ]^$ex1}{$n6})^0  }{ $n6a^$ex2 \\times  \\frac{ $n6a^$ex3}{ $n6b^$ex2 \\times $n6a} \\times  \\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n3} \\times \\frac{[($n6^$ex4 )^{$ep} ]^$ex1}{$n6}} \)</p> ";
            } 
             echo '</div>';

        }

?>

            </div>
            <button id="btnDescargarPDF" class="btn btn-primary mb-3">Descargar PDF</button>
        </div> 

    </main>

    <!-- Agregar referencia a la biblioteca html2pdf -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.9.2/html2pdf.bundle.min.js"></script>
    <script>
        document.getElementById('btnDescargarPDF').addEventListener('click', function() {
            // Asegurarse de que MathJax ha terminado de renderizar
            MathJax.Hub.Queue(function() {
                var element = document.querySelector('.list-group');
                var options = {
                    margin:       0.5,
                    filename:     'ejercicios.pdf',
                    image:        { type: 'jpeg', quality: 1.5 },
                    html2canvas:  { 
                        scale: 4, // Aumenta el valor de 'scale' para mejorar la calidad
                        logging: true, // Desactivar el logging si no es necesario
                        useCORS: true // Habilita CORS si es necesario
                    },
                    jsPDF:        { 
                        unit: 'in', 
                        format: 'letter', 
                        orientation: 'portrait' 
                    }
                };
                html2pdf().from(element).set(options).save();
            });
        });
    </script>

    <script>
        MathJax.typeset();
    </script>
    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
    </main>
    <?php include 'subir1.php'; ?>
</body>
</html>
