<!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=rand(1,20);
?>
          
            <h10 class="card-title">Ejercicio <?php echo $i; ?></h10>
              <?php
              switch($ejercicio) {


                case 1:
                  echo "<p class='card-text'> \( \sqrt{ $n2^{-$ex4}}  \)</p>";
                  
                  break;
                case 2:
                  echo "<p class='card-text'> \( \sqrt{ $n2^{-$ex1} } \\times \sqrt{ $n2^{$ex3} }   \)</p>";
                  break;
                case 3:
                  echo "<p class='card-text'> \( \sqrt{ $n2^{$ex2} } \div \sqrt{ $n2^{$ex3} }   \)</p>";
                  break;
                case 4:
                  echo "<p class='card-text'> \( (\sqrt{ $n2^{-$ex4}})^$ex2  \)</p>";
                  break;
                case 5:
                  echo "<p class='card-text'> \( \sqrt{\sqrt{(($n5^{-$ex6} \\times $n5^$ex7 \\times $n5^$ex8 \\times $n5^{-$ex9})^$ex1)}} \)</p> ";
                  break;
                   case 6:
                   $ep1=$ep*2;
                echo "<p class='card-text'> \( \sqrt[$ep]{\sqrt{(($n5^$ex8 \\times $n5^{-$ex9})^$ex1)^$ep1}} \)</p> ";
                    break;
                
                case 7:
                 $ep=$ep+1;
                $ex9=$ex9*2;
                 $ep1=$ep*2;
                echo "<p class='card-text'> \( \sqrt[$ep]{\sqrt{(($n5^$ex8 \\times \sqrt{ $n5^{-$ex9}})^$ex1)^$ep1}} \)</p> ";
                break;
                case 8:
               $epf=rand(2,3);;
               $ep=$ep+1;
                $ex9=$ex9*2;
                 $ep1=$ep*2;
                 $n5 = rand(2,4);
               $n5a = pow($n5,($epf));
               $n5b = pow($n5,($epf+1));
                echo "<p class='card-text'> \( \sqrt[$ep]{\sqrt{(($n5a^$ex8 \\times \sqrt{ $n5b^{-$ex9}})^$ex1)^$ep1}} \div \sqrt[$ep]{\sqrt{(($n5^$ex8 \\times $n5a^{-$ex9})^$ex1)^$ep1}} \)</p> ";
                break;
                case 9:
                $epf=rand(2,3);;
               $ep=$ep+1;
                $ex9=$ex9*2;
                 $ep1=$ep*2;
                 $n5 = rand(2,3);
               $n5a = pow($n5,($epf));
               $n5b = pow($n5,($epf+1));
                echo "<p class='card-text'> \( \sqrt{\sqrt[$ep]{\sqrt{(($n5a^$ex8 \\times \sqrt{ $n5b^{-$ex9}})^$ex1)^$ep1}} \\times (\sqrt[$ep]{\sqrt{(($n5^$ex8 \\times $n5a^{-$ex9})^$ex1)^$ep1}})^0 } \)</p> ";
                break;
                case 10:
                echo "<p class='card-text'> \(\\sqrt{ \\left(\\frac{ ($n2^$ex1 \\times $n2^$ex3)^$ex4 \\times $n2^{-$ex2}}{ $n2^$ex4 \\times $n2^$ex5 \\times $n2^{-$ex6}} \\right)^$ex9} \)</p>"; 

                break;
                case 11:
                echo "<p class='card-text'> \( \\sqrt {\\sqrt{\\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:
                $epf=rand(2,3);;
               $ep=$ep+1;
                $ex9=$ex9*2;
                 $ep1=$ep*2;

                echo "<p class='card-text'> \( \\sqrt[$ex9]{($n5^$ex2 \div $n5^{-$ex3}   \\times $n5^$ex4 \\times $n5^{-$ex5}   \div $n5^$ex5 \\times $n5^{-$ex8})^{-$ex9} }  \)</p>";
                break;
                case 13:
                echo "<p class='card-text'> \( \\sqrt{[($n6^$ex4 \\times $n6^$ex3)^{-8} \div $n6^{-$ex1}]^$ex6} \\times \\sqrt[$ex2]{(($n6^$ex2 )^1)^1}  \div \\sqrt{ $n6^$ex4 \\times $n6 }  \)</p>";
                break;
                case 14:
                $n6 = rand(2,4);
                $ex1=[2,4,6];
                $ex = $ex1[array_rand($ex1)];
               $n6a = pow($n6,($ep));
               $n6b = pow($n6,($ep+1));
                echo "<p class='card-text'> \(  \\frac{(\\sqrt{ $n6^{".($ex+2)."}} \\times $n6a^{".($ex+4)."})^{-8}}{ $n6b^$ex \\times $n6} \div \\sqrt[$ex]{\\frac{[($n6^{".($ex+4)."} \div $n6^{".($ex+2)."})^{-8} \\times $n6c^{-".($ex+6)."}]^$ex}{ \\sqrt{ $n6b^{".($ex+2)."}}}} \)</p> "; 
                break;
                case 15:
                $n6 = rand(2,4);
               $n6a = pow($n6,($ep));
               $n6b = pow($n6,($ep+1));
                echo "<p class='card-text'> \(  \\sqrt{\\sqrt[3]{\\sqrt{\\left(\\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n3}\\right)^2 \div \\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'> \(  \\sqrt{\\frac{ $n6a^$ex1}{ $n6b^$ex2 \div $n3}} \div \\sqrt[$ex5]{\\frac{[($n6^$ex4 \div $n6^$ex5)^{$ep} ]^$ex1}{$n6}} \div $n6a^$ex1 \div \\sqrt{ $n3^0}  \)</p> ";
                
                break;
                case 17:
                $n6 = rand(2,4);
               $n6a = pow($n6,($ep));
               $n6b = pow($n6,($ep+1));
                echo "<p class='card-text'> \(  \\sqrt{\\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n3} \\times \\sqrt[$ex2]{\\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{\\sqrt{\\left(\\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n6}\\right)^2 \\times \\left(\\frac{[($n6^$ex4 \div $n6^$ex5)^{$ep} ]^$ex1}{$n6}\\right)^1 } }{ \\sqrt{ $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{\\sqrt{\\left(\\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n6}\\right)^2 \\times \\left(\\frac{[($n6^$ex4 \div $n6^$ex5)^{$ep} ]^$ex1}{$n6}\\right)^1 } }{ \\sqrt{ $n6a^$ex2 \\times  \\frac{ $n6a^$ex3}{ $n6b^$ex2 \\times $n6a}} } \div \\sqrt[3]{\\sqrt{ \\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'> \( \\sqrt   {\\sqrt[$ex2]{\\sqrt{\\frac{\\sqrt{\\left(\\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n6}\\right)^2 \\times \\left(\\frac{[($n6^$ex4 \div $n6^$ex5)^{$ep} ]^$ex1}{$n6}\\right)^0 } }{ \\sqrt{ $n6a^$ex2 \\times  \\frac{ $n6a^$ex3}{ $n6b^$ex2 \\times $n6a}} } \div \\sqrt[3]{\\left(\\sqrt{ \\frac{ $n6a^$ex1}{ $n6b^$ex2 \\times $n3} \\times \\frac{[($n6^$ex4 )^{$ep} ]^$ex1}{$n6}}\\right)^$ex1}}}}\)</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>
        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: 5, // 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: 'A4', 
                        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>
