<!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="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <?php include 'encabezado.php'; ?>
    <main>
        <?php include 'menui.php'; ?>
        <div class="container mt-5 overflow-auto">
            <!-- Botón de descarga -->
            <h3>Simplificación de terminos semejantes</h3>
            <div class="list-group">

                <?php
                    for ($i = 1; $i <= $n; $i++) {
                        $n1 = rand(4,10); 
                        $n2 = rand(4,10);
                        $n3 = rand(4,10);
                        $n4 = rand(4,10);
                        $n5 = rand(4,10);
                        $n6 = rand(4,10);
                        $n7 = rand(4,10);
                        $n8 = rand(4,10);
                        $n9 = rand(4,10);
                        $ex1 = rand(2,4);
                        $ex2 = rand(5,6);
                        $ex3 = rand(7,8);
                        $ejercicio = rand(1,20);

                        $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', 'x^5n'];
                        $f = ['axy', 'xyb', 'x^2yb', 'xy^2c'];

                        $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)];

                        echo "<div class='card mb-3'>";
                        echo "<div class='card-body'>";
                        echo "<h5 class='card-title'>Ejercicio $i</h5>";
                        switch ($ejercicio) {
                            case 1:
                                echo "<p class='card-text'>\\($n1 $a1 - $n2 y - $n3 $a1\\)</p>";
                                break;
                            case 2:
                                echo "<p class='card-text'>\\($n1 a - $n2 a - $n3 $a1 - $n4 $a1\\)</p>";
                                break;
                            case 3:
                                echo "<p class='card-text'>\\($n4 b - $n6 c - $n7 b - $n8 b + $n1 c - $n2 a - $n3 a\\)</p>";
                                break;
                            case 4:
                                echo "<p class='card-text'>\\($n4 b - $n6 c^2 - $n7 b - $n8 b + $n1 c^2 - $n2 a - $n3 a\\)</p>";
                                break;
                            case 5:
                                echo "<p class='card-text'>\\($n2 $a1 + $n4 x^2 - $n6 $a1 + $n8 b + $n1 x^2 - $n3 $a1 p - $n4 b\\)</p>";
                                break;
                            case 6:
                                echo "<p class='card-text'>\\($n1 xyz + $n2 x^2n - $n3 xyz + $n4 b + $n5 x^2n - $n6 xy - $n4 b\\)</p>";
                                break;
                            case 7:
                                echo "<p class='card-text'>\\($n1 x^$ex1 yz - $n2 x^2 n - $n3 x^$ex1 yz - $n4 b + $n5 x^2 n - $n6 xy + $n4 b^$ex2\\)</p>";
                                break;
                            case 8:
                                echo "<p class='card-text'>\\(-$n8 $a1^$ex1 - $n6 y - $n5 $a1^$ex1\\)</p>";
                                break;
                            case 9:
                                echo "<p class='card-text'>\\($n1 $a1 + $n2 $a1 - $n3 $a1 + $n4 $a1\\)</p>";
                                break;
                            case 10:
                                echo "<p class='card-text'>\\($n1 $b1 + $n2 $b1 - $n3 $b1 - $n4 $b1\\)</p>";
                                break;
                            case 11:
                                echo "<p class='card-text'>\\($n1 $c1 + $n2 $c1 - $n3 $c1 - $n4 $c1\\)</p>";
                                break;
                            case 12:
                                echo "<p class='card-text'>\\($n4 $b1 + $n6 c^2 + $n7 $b1 - $n8 $b1 - $n1 c^2 - $n2 a + $n3 $c1\\)</p>";
                                break;
                            case 13:
                                echo "<p class='card-text'>\\(-$n1 $c1 - $n2 $c1 - $n3 $d1 + $n4 $d1 - $n3 $c1 - $n4 $c1 - $n5 $d1 + $n6 $d1\\)</p>";
                                break;
                            case 14:
                                echo "<p class='card-text'>\\($n1 $b1^$ex3 - $n6 c^2 - $n2 $b1^$ex3 + $n3 $b1^$ex3 - $n1 c^2 + $n2 a - $n3 $b1 - $n2 $b1^$ex3 - $n3 c^2\\)</p>";
                                break;
                            case 15:
                                echo "<p class='card-text'>\\($n4 $c1^$ex3 - $n5 $c1^$ex3 - $n6 $c1^$ex3 - $n7 $c1 + $n3 $c1^$ex3 - $n2 $c1^$ex3 - $n1 $c1\\)</p>";
                                break;
                            case 16:
                                echo "<p class='card-text'>\\(-$n5 $b1^$ex2 - $n5 c^9 + $n6 $b1^$ex2 + $n7 $b1^$ex2 - $n1 c^9 + $n2 a + $n5 $b1 - $n4 $b1^$ex3 + $n2 c^9\\)</p>";
                                break;
                            case 17:
                                echo "<p class='card-text'>\\(-$n3 $b1^$ex1 + $n6 c^2 - $n4 $b1^$ex1 + $n5 $b1^$ex1 - $n1 c^2\\)</p>";
                                break;
                            case 18:
                                echo "<p class='card-text'>\\(-$n9 $b1^$ex1 - $n7 $b1^$ex1\\)</p>";
                                break;
                            case 19:
                                echo "<p class='card-text'>\\(-$n3 $f1^$ex1 + $n6 cx^4 - $n4 $f1^$ex1 + $n5 $f1^$ex1 - $n1 cx^4\\)</p>";
                                break;
                            case 20:
                                echo "<p class='card-text'>\(-$n5$f1^{$ex2} - $n5$f1^{$ex2} + $n6$f1^{$ex2} + $n7$e1^{$ex3} - $n1$f1^{$ex3} + $n2$a1^{$ex2} + $n5$b1 - $n4$e1^{$ex3} + $n2$f1^{$ex3}\)</p>";
                                break;
                        }
                        echo "</div>";
                        echo "</div>";
                    }
                ?>
            </div>
            
        </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() {
            var element = document.querySelector('.list-group');
            var options = {
                margin:       0.5,
                filename:     'ejercicios.pdf',
                image:        { type: 'jpeg', quality: 0.98 },
                html2canvas:  { scale: 3 },
                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>
    <?php include 'subir.php'; ?>
</body>
</html>
