<!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'; ?>
     <?php include 'menui.php'; ?>
    <main>
   
    <div class="container mt-5">
        <h3 class="mb-4">Operaciones Combinadas con signos de agrupación</h3>
        <div class="mt-4">
            <?php
                function generateExpression() {
                    $operators = ['+', '-', '*', '/'];
                    $operators1 = ['+', '-', '*'];
                    $expression = "";
                    $numTerms = rand(3, 15); // Number of terms in the expression
                    $r = rand(2,5);
                    $a = rand(2,5);
                    $b= rand(2,5);
                    $c = rand(2,5);
                    $d = rand(2,5);
                    $e = rand(2,15);
                    $f = rand(2,15);
                    $g= rand(2,15);
                    $h= rand(2,15);
                    $i = rand(2,25);
                    $j = rand(2,25);
                    $di = rand(2,25);
                    $di1 = $di*$a;
                    $k = rand(2,25);
                    $l= rand(2,25);
                    $m = rand(2,35);
                    $o= rand(2,35);
                    $p = rand(2,35);
                    $sorteo = rand(1,30);
                    
                    $de = rand(2,30);
                    $nu = $de*$a;
                    $de1 = rand(2,30);
                    $nu1 = $de1*$b;
                    $de2 = rand(2,30);
                    $nu2 = $de2*$c;
                    $de3 = rand(2,30);
                    $nu3 = $de3*$d;
                    $de4 = rand(2,30);
                    $nu4 = $de4*$e;

                  

                    if ($sorteo==1)
                    {
                        $expression="$a + \{ $d \\times [ $b + ($e - $c) ] \}";
                    }
                    if ($sorteo==2)
                    {
                        $expression="$a + $b \\times \{ $c + [ $d \\times ($e - $a) ] \} - $b";
                    }

                    if ($sorteo==3)
                    {
                        $expression="$a + \{ $d \\times [ $b + ($e - $c+ ($e - $c)) - ($a - $c) ] \}";
                    }
                    if ($sorteo==4)
                    {
                        $expression="($a \\times $b \\times \{ $c + [ $d \\times ($e - $a) ] \} \\times $b)";
                    }
                    if ($sorteo==5)
                    {
                        $expression=" [$a + ($d + $d) ] \\times $a - ($b - $c)";
                    }
                    if ($sorteo==6)
                    {
                        $expression=" [$a - ($b - $c)] - [$a\\times ($f + $g)]"; 
                    }

                    if ($sorteo==7)
                    {
                         $expression=" $a\\times {($f + $g) [$a\\times ($f + $g)]} "; 
                     }
                    if ($sorteo==8)
                    {
                       $expression=" $a \\times $a \div ($a + $a)";
                    }
                    if ($sorteo==9)
                    {
                       $expression=" $f + ($a\\times $b) - $g - ( $h + 2) \\times $i";
                    }
                    if ($sorteo==10)
                    {
                        $expression="($a+ $b ) \\times ($c  - $d )"; 
                    }
                    if ($sorteo==11)
                    {
                        $expression="($di1  \\div $di ) + ($e  \\times $f)"; 
                    }

                    if ($sorteo==12)
                    {
                         $expression="$g - ( $h + 2) \\times $i - ($di1  \\times $di ) \\div ($di )";
                    }
                    if ($sorteo==13)
                    {
                       $expression="($di1  \\times $di ) \\div ($di )"; 
                    }
                    if ($sorteo==14)
                    {
                       $expression="$j  \\times [$k  + ($di1  \\div $di )]";
                    }
                    
                    if ($sorteo==15)
                    {
                       $expression="$a + \\{[($b +$c + $d) + $e + $f + ($g - $h + $i)] + ($j - $k - $l)\\} - $j";
                    }

                    if ($sorteo==16)
                    {
                       $expression="$a + \\{ [(-($b) + $c) + $d] + [($e + $f) + $g - $h + $i + ($j - $k) - $l] \\} - $j";
                    }

                    if ($sorteo==17)
                    {
                       $expression="$a + \\{ $b - [($c + $d) - $e + ($f - $g)] + [$h + ($i + $j) - $k] \\}+ $l - $j";
                    }
                    if ($sorteo==18)
                    {
                       $expression="\\{ $a + [($b - $c) + $d - $e]\\} + \\{[($f - $g) + $h - $i] + ($j - $k + $l)\\} - $j";
                    }


                    if ($sorteo==19)
                    {
                       $expression="$a \\times \\{[($b +$c + $d) + $e + $f \\times ($g - $h + $i)] + ($j - $k - $l)\\} \\times $j";
                    }

                    if ($sorteo==20)
                    {
                       $expression="$a + \\{ [(-($b) + $c) \\times $d] + [($e + $f) + $g - $h \\times $i + ($j - $k) - $l] \\} \\times $j";
                    }

                    if ($sorteo==21)
                    {
                       $expression="$a \\times \\{ $b - [($c + $d) - $e \\times ($f - $g)] + [$h + ($i + $j) - $k] \\}+ $l \\times $j";
                    }
                    if ($sorteo==22)
                    {
                       $expression="\\{ $a + [($b \\times $c) + $d - $e]\\} + \\{[($f - $g) \\times $h - $i] + ($j - $k + $l)\\} \\times $j";
                    }
                    if ($sorteo==23)
                    {
                       $expression="\\{ $a + [($b \\times $c) + $nu \\div $de - $e]\\} + \\{[($f - $g) \\times $h - $i] + ($j - $k + $l)\\} \\times $j";
                    }

                    if ($sorteo==24)
                    {
                       $expression="$a + \\{ $b - [($c + $d) - $nu \\div $de + ($f - $g)] + [$h + ($i + $j) - $nu1 \\div $de1 ] \\}+ $l - $j";
                    }
                    if ($sorteo==25)
                    {
                       $expression="\\{ $a + [($b - $c) + $nu \\div $de - $e]\\} + \\{[($f - $nu1 \\div $de1) + $h - $i] + ($j - $nu2 \\div $de2 + $l)\\} - $j";
                    }


                    if ($sorteo==26)
                    {
                       $expression="$nu \\div $de \\times \\{[($b +$nu2 \\div $de2 + $d) + $nu3 \\div $de3 + $f \\times ($g - $nu4 \\div $de4 + $i)] + ($j - $k - $l)\\} \\times $j";
                    }

                    if ($sorteo==27)
                    {
                       $expression="$a + \\{ [(-($b) + $nu1 \\div $de1) \\times $d] + [($e + $f) + $g - $h \\times $i + ($j - $k) - $nu \\div $de] \\} \\times $j";
                    }

                    if ($sorteo==28)
                    {
                       $expression="$a \\times \\{ $nu \\div $de - [($c + $nu1 \\div $de1) - $e \\times ($f - $g)] + [$nu2 \\div $de2 + ($i + $j) - $k] \\}+ $nu3 \\div $de3 \\times $nu \\div $de";
                    }
                    if ($sorteo==29)
                    {
                       $expression="\\{ $a + [($b \\times $nu \\div $de) + $nu3 \\div $de3 - $e]\\} + \\{[($f - $g) \\times $h - $i] + ($j - $nu2 \\div $de2 + $l)\\} \\times $j";
                    }
                    


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

                          




                    




                    //
                    //expression="$a + {$b - [($c + $d) - $e + ($f - $g)] + [$h + ($i + $j) - $k] }+ $l - $j";
                    //expression="";
                    //expression="$a + $b - $c + $d - $e + $f - $g + $h - $i + $j - $k + $l - $j";
                    //expression="$a + $b + $c + $d + $e + $f + $g - $h + $i + $j - $k - $l - $j";
                    //expression="$a + $b - $c + $d - $e + $f - $g + $h + $i + $j - $k + $l - $j";
                    //expression="$a + $b - $c + $d - $e + $f - $g + $h - $i + $j - $k + $l - $j";
                    //expression="$a + $b - $c + $d - $e + $f - $g + $h - $i + $j - $k + $l - $j";


 



    
   
    
    






$result=1;
                    return [$expression, $result];
                }

                for ($i = 1; $i <= $n; $i++) {
                    list($expression, $result) = 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>
     

             
    
    <!-- Scroll to Top Button -->
    

    <!-- 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>
