<!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 -->
            <h3>Resta de Polinomios</h3>
            <div class="list-group">

                <?php
$ejercicio=0;
            for ($i = 1; $i <= $n; $i++) {
                
                echo '<div class="card mb-3">';
                   
                    
                   


               
               

$ejercicio=rand(1,5);
?> 
          
            <h10 class="card-title">Ejercicio <?php echo $i; ?></h10>
              <?php
              switch($ejercicio) {


                case 1:
               $a = ['a', 'b', 'x^2yb', 'xy^2c', 'b^2cb', 'ab^3c', 'a^2db^3', 'xy^2c^7'];
               $b = ['x', 'y', 'x^2yb', 'xy^2c', 'x^2y^3zb', 'xy^4z^2c', 'x^2y^5zb', 'xy^6z^2c'];
               $c = ['m', 'n', 'm^2ab', 'ny^2b', 'm^2a^2b', 'ny^2b^2', 'm^2a^3b', 'ny^2b^4'];
               $d = ['ab', 'xy', 'x^2y', 'xy^2', 'x^2yz', 'w^2xy^2z', 'w^3x^2yz', 'w^4xy^2z'];
               $e = ['cd', 'mn', 'm^2y', 'xa^2n^2', 'na^3m^2yz', 'wa^4xn^2z', 'wm^2ya^5z', 'wxa^6n^2z'];
               $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)];
               $n1=rand(2,40);
               $n2=rand(2,40);
               $n3=rand(2,40);
               $n4=rand(2,40);
               $n5=rand(2,40);

                  echo "<p class='card-text'> \( ( $n1 $a1+$n2$b1)-( $n3$a1 - $n4$b1)  \)</p>";
                  
                  break;
                case 2:
                 $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)];
               $n1=rand(2,40);
               $n2=rand(2,40);
               $n3=rand(2,40);
               $n4=rand(2,40);
               $n5=rand(2,40);

                  echo "<p class='card-text'> \( ( $n1 $a1+$n2$b1-$n2$c1)-($n2$c1 + $n3$a1 - $n4$b1)  \)</p>";
                  break;
                case 3:
                 $a = ['a', 'b','c', 'd', 'x^2yb', 'xy^2c'];
               $b = ['x', 'y', 'z', 'w','x^2yb', 'xy^2c'];
               $c = ['m', 'n', 'm^2ab', 'ny^2b'];
               $d = ['ab', 'xy','cd', 'ef', 'x^2y^3mn^5', 'x^4y^2zw'];
               $e = ['pq', 'mn', 'm^2y', 'xn^2'];
               $f = ['axyz', 'xybz', 'x^2yb^3', 'xy^2c^4'];
               $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)];
               $n1=rand(2,40);
               $n2=rand(2,40);
               $n3=rand(2,40);
               $n4=rand(2,40);
               $n5=rand(2,40);

                  echo "<p class='card-text'> \( ( $n1 $d1+$n2$b1-$n2$f1)-($n2$f1 + $n3$d1 - $n4$b1)  \)</p>";
                  break;
                case 4:
                 $a = ['a', 'b','c', 'd', 'x^2yb', 'xy^2c'];
               $b = ['x', 'y', 'z', 'w','x^2yb', 'xy^2c'];
               $c = ['m', 'n', 'm^2ab', 'ny^2b'];
               $d = ['ab', 'xy','cd', 'ef', 'x^2y^3mn^5', 'x^4y^2zw'];
               $e = ['pq', 'mn', 'm^2y', 'xn^2'];
               $f = ['axyz', 'xybz', 'x^2yb^3', 'xy^2c^4'];
               $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)];
               $n1=rand(2,40);
               $n2=rand(2,40);
               $n3=rand(2,40);
               $n4=rand(2,40);
               $n5=rand(2,40);

                  echo "<p class='card-text'> \( ( $n1$d1+$n2$b1-$n2$e1+$n3$a1-$n4$c1)-($n2$a1 + $n3$b1 - $n4$c1 - $n5$d1 - $n1$e1)  \)</p>";
                  break;
                case 5:
                 $a = ['a', 'b','c', 'd', 'x^2yb', 'xy^2c'];
               $b = ['x', 'y', 'z', 'w','x^2yb', 'xy^2c'];
               $c = ['m', 'n', 'm^2ab', 'ny^2b'];
               $d = ['ab', 'xy','cd', 'ef', 'x^2y^3mn^5', 'x^4y^2zw'];
               $e = ['pq', 'mn', 'm^2y', 'xn^2'];
               $f = ['axyz', 'xybz', 'x^2yb^3', 'xy^2c^4'];
               $a1 = $a[array_rand($a)];
               $b1 = $b[array_rand($b)];
               $c1 = $c[array_rand($c)];
               $d1 = $d[array_rand($d)];
               $e1 = $e[array_rand($e)];
               $f1 = $f[array_rand($f)];
               $n1=rand(2,40);
               $n2=rand(2,40);
               $n3=rand(2,40);
               $n4=rand(2,40);
               $n5=rand(2,40);

                  echo "<p class='card-text'> \( ( $n1$f1+$n2$b1-$n2$e1+$n3$a1)-($n2$a1 + $n3$b1  - $n5$f1 - $n1$e1)  \)</p>";
                  break;
                 
                
                
                
            } 
             echo '</div>';

        }

?>

            </div>
            
        </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 'subir.php'; ?>
</body>
</html>
