<!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>
    <main>
        <?php include 'encabezado.php'; ?>
    <?php include 'menui.php'; ?>
    <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 = ['+', '-', '*'];
                    $ex = [2,3,4,5,6,7,8,9];
                    $exf = [2,3,4];

                    $ex1 = $ex[array_rand($ex)];
                    $ex2 = $ex[array_rand($ex)];
                    $ex3 = $ex[array_rand($ex)];
                    $ex4 = $ex[array_rand($ex)];
                    $ex5 = $ex[array_rand($ex)];
                    $exp1 = $exf[array_rand($exf)];
                    $exp2 = $exf[array_rand($exf)];
                    $exp3 = $exf[array_rand($exf)];
                    $exp4 = $exf[array_rand($exf)];
                    $exp5 = $exf[array_rand($exf)];
                    $exp6 = $exf[array_rand($exf)];
                    $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,33);
                    $bas = rand(2,4);
                    $bas1 = rand(2,4);
                    $bas2 = rand(2,4);
                    $bas3 = rand(2,4);
                    
                    $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 + \{ 2^$ex1 \\times [ 2^$ex2 + ($e - $c) ] \}";
                    }
                    if ($sorteo==2)
                    {
                        $expression="$a + 2^$ex2 \\times \{ $c + [ $d \\times ($bas2^$exp2 - $a) ] \} - 2^$ex1";
                    }

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

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

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

                    if ($sorteo==16)
                    {
                       $expression="$a + \\{ [(-($b) + $bas1^$exp1) + $bas2^$exp2] + [($e + $f) + $g - $h + $i + ($j - $k) - $l] \\} - $j";
                    }

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


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

                    if ($sorteo==20)
                    {
                       $expression="$bas2^$exp2 + \\{ [(-($b) + $bas1^$exp1) \\times $bas2^$exp2] + [($e + $f) + $g - $h \\times $i + ($j - $k) - $l] \\} \\times $j";
                    }

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

                    if ($sorteo==24)
                    {
                       $expression="$a + \\{ $b - [($c + $bas2^$exp2) - $nu \\div $de + ($bas1^$exp1 - $g)] + [$h + ($i + $j) - $nu1 \\div $de1 ] \\}+ $bas3^$exp3 - $j";
                    }
                    if ($sorteo==25)
                    {
                       $expression="\\{ $a + [($bas1^$exp1 - $c) + $nu \\div $de - $e]\\} + \\{[($f - $nu1 \\div $de1) + $h - $i] + ($j - $nu2 \\div $bas3^$exp3 + $l)\\} - $j";
                    }


                    if ($sorteo==26)
                    {
                       $expression="$nu \\div $de \\times \\{[($b +$nu2 \\div $de2 + $bas2^$exp2) + $nu3 \\div $de3 + $f \\times ($bas1^$exp1 - $nu4 \\div $de4 + $bas3^$exp3)] + ($j - $k - $l)\\} \\times $j";
                    }

                    if ($sorteo==27)
                    {
                       $expression="$a + \\{ [(-($b) + $nu1 \\div $de1) \\times $d] + [($e + $bas2^$exp2) + $g - $h \\times $i + ($bas1^$exp1 - $k) - $bas3^$exp3 \\div $de] \\} \\times $j";
                    }

                    if ($sorteo==28)
                    {
                       $expression="$a \\times \\{ $nu \\div $de - [($c + $nu1 \\div $de1) - $e \\times ($f - $g)] + [$nu2 \\div $de2 + ($bas1^$exp1 + $bas2^$exp2) - $bas3^$exp3] \\}+ $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 - $bas1^$exp1] + ($j - $nu2 \\div $de2 + $bas2^$exp2)\\} \\times $bas3^$exp3";
                    }

                    if ($sorteo==30)
                    {
                        $expression="$a + \{ 2^$ex1 \\times [ 2^$ex2 + ($e - $c) ] \}^1";
                    }
                    if ($sorteo==31)
                    {
                        $expression="$a + 2^$ex2 \\times \{ $c + [ $d \\times ($bas2^$exp2 - $a)^0 ] \} - 2^$ex1";
                    }

                    if ($sorteo==32)
                    {
                        $expression="$a + \{ $d \\times [ 2^$ex1 + ($e^0 - $bas2^$exp2 + ($e - $c)) - ($a - $c) ] \}";
                    }
                    if ($sorteo==33)
                    {
                        $expression="($a \\times 2^$ex3 \\times \{ 2^$ex1 + [ $d \\times ($e - $bas2^$exp2) ]^0 \} \\times $b)";
                    }
                    if ($sorteo==34)
                    {
                        $expression="\\sqrt{\\sqrt{\\sqrt{\\sqrt[3]{$a}}}}";
                    }
                    



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