<!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>
    <!-- Bootstrap CSS -->
    <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">
        <h3 class="mb-4">Ejercicios de Ecuaciones</h3>
        <div class="mt-4">
            <?php
                function generateExpression() {
                    $operators = ['+', '-','x'];
                    $operators1 = ['+', '-', 'x'];
                    $operatorss1 = ['+', '-'];
                    $expression = "";
                    $expression1 = "";
                    $numTerms = rand(3, 10); // Number of terms in the expression
                    $numTerms2 = rand(2, 8);
                    $r = rand(2,5);
                    

                    for ($i = 0; $i < $numTerms; $i++) {
                        $number = rand(1, 10);
                        $operator = $operators[array_rand($operators)];
                        $operator1 = $operators1[array_rand($operators1)];
                        $operatorss = $operatorss1[array_rand($operatorss1)];

                     if ($operator == "x")

                     {
                        
                        if ($i == 0) {
                            $expression .= "$operatorss $number$operator";
                        } else {
                            
                            $expression .= "$operatorss $number$operator" ;
                        }

                     }
                 else {
                       
                        if ($i == 0) {
                            $expression .= "$operator $number";
                        } else {
                            $expression .= "$operator $number";
                        }
                    }

                        }


                
                        for ($i = 0; $i < $numTerms2; $i++) {
                        
                        $number = rand(1, 10);
                         $operator = $operators[array_rand($operators)];
                        $operator1 = $operators1[array_rand($operators1)];
                        $operatorss = $operatorss1[array_rand($operatorss1)];
                        
                        

                     if ($operator1 == "x")

                     {
                        
                        if ($i == 0) {
                            $expression1 .= "$operatorss$number$operator1";
                        } else {
                            $expression1 .= "$operatorss$number$operator1";
                        }

                     }
                 else {
                       
                        if ($i == 0) {
                            $expression1 .= "$operator1$number";
                        } else {
                            $expression1 .= "$operator1$number";
                        } 
                    }

                    }

                        $expressionf = "$expression = $expression1";
                    return [$expressionf];


}


                        
                    // Evaluate the expression
                    //$result = eval("return $expression;");

                    
                for ($i = 1; $i <= $n; $i++) {
                    list($expression) = generateExpression();
                    echo "<div class='card mb-3'>";
                    echo "<div class='card-body'>";
                    echo "<h5 class='card-title'>Ejercicio $i</h5>";
                    echo "<p class='card-text'>Expresión: \\( $expression \\)</p>";
                    //echo "<p class='card-text'>Resultado: \\( $result \\)</p>";
                    echo "</div>";
                    echo "</div>";
                }
            ?>
        </div>
         
    </div>
    <!-- MathJax -->
    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</main>
 <?php include 'subir.php'; ?>
</body>
</html>
