Foro de elhacker.net

Programación => Programación General => Mensaje iniciado por: Tachikomaia en 18 Agosto 2018, 04:21 am



Título: (Resuelto): Errores en generador de sentencias condicionales.
Publicado por: Tachikomaia en 18 Agosto 2018, 04:21 am
EDIT:
Solución en el 2ndo post. Dejo el tema por si a alguno le interesa, pero si quieren bórrenlo o ciérrenlo.

El resultado que intenté obtener sería así:
Citar
V1 < V1
V1 < V2
V1 <= V1
V1 <= V2
V1 == V1
V1 == V2
V1 != V1
V1 != V2
V1 < V1
V2 < V1
V1 <= V1
V2 <= V1
V2 < V1
V2 < V2
V2 <= V1
V2 <= V2
V2 == V1
V2 == V2
V2 != V1
V2 != V2
V1 < V2
V2 < V2
V1 <= V2
V2 <= V2

24
2 variables * 6 símbolos * 2 variables

V1 < V1 && V1 < V1
V1 < V1 && V1 < V2
V1 < V1 && V1 < V3
V1 < V1 && V1 < V4
V1 < V1 && V1 <= V1
V1 < V1 && V1 <= V2
V1 < V1 && V1 <= V3
V1 < V1 && V1 <= V4
V1 < V1 && V1 == V1
V1 < V1 && V1 == V2
V1 < V1 && V1 == V3
V1 < V1 && V1 == V4
V1 < V1 && V1 != V1
V1 < V1 && V1 != V2
V1 < V1 && V1 != V3
V1 < V1 && V1 != V4
V1 < V1 && V1 < V1
V1 < V1 && V2 < V1
V1 < V1 && V3 < V1
V1 < V1 && V4 < V1
V1 < V1 && V1 <= V1
V1 < V1 && V2 <= V1
V1 < V1 && V3 <= V1
V1 < V1 && V4 <= V1
V1 < V1 && V2 < V1
V1 < V1 && V2 < V2
V1 < V1 && V2 < V3
V1 < V1 && V2 < V4
V1 < V1 && V2 <= V1
V1 < V1 && V2 <= V2
V1 < V1 && V2 <= V3
V1 < V1 && V2 <= V4
V1 < V1 && V2 == V1
V1 < V1 && V2 == V2
V1 < V1 && V2 == V3
V1 < V1 && V2 == V4
V1 < V1 && V2 != V1
V1 < V1 && V2 != V2
V1 < V1 && V2 != V3
V1 < V1 && V2 != V4
V1 < V1 && V1 < V2
V1 < V1 && V2 < V2
V1 < V1 && V3 < V2
V1 < V1 && V4 < V2
V1 < V1 && V1 <= V2
V1 < V1 && V2 <= V2
V1 < V1 && V3 <= V2
V1 < V1 && V4 <= V2
V1 < V1 && V3 < V1
V1 < V1 && V3 < V2
V1 < V1 && V3 < V3
V1 < V1 && V3 < V4
V1 < V1 && V3 <= V1
V1 < V1 && V3 <= V2
V1 < V1 && V3 <= V3
V1 < V1 && V3 <= V4
V1 < V1 && V3 == V1
V1 < V1 && V3 == V2
V1 < V1 && V3 == V3
V1 < V1 && V3 == V4
V1 < V1 && V3 != V1
V1 < V1 && V3 != V2
V1 < V1 && V3 != V3
V1 < V1 && V3 != V4
V1 < V1 && V1 < V3
V1 < V1 && V2 < V3
V1 < V1 && V3 < V3
V1 < V1 && V4 < V3
V1 < V1 && V1 <= V3
V1 < V1 && V2 <= V3
V1 < V1 && V3 <= V3
V1 < V1 && V4 <= V3
V1 < V1 && V4 < V1
V1 < V1 && V4 < V2
V1 < V1 && V4 < V3
V1 < V1 && V4 < V4
V1 < V1 && V4 <= V1
V1 < V1 && V4 <= V2
V1 < V1 && V4 <= V3
V1 < V1 && V4 <= V4
V1 < V1 && V4 == V1
V1 < V1 && V4 == V2
V1 < V1 && V4 == V3
V1 < V1 && V4 == V4
V1 < V1 && V4 != V1
V1 < V1 && V4 != V2
V1 < V1 && V4 != V3
V1 < V1 && V4 != V4
V1 < V1 && V1 < V4
V1 < V1 && V2 < V4
V1 < V1 && V3 < V4
V1 < V1 && V4 < V4
V1 < V1 && V1 <= V4
V1 < V1 && V2 <= V4
V1 < V1 && V3 <= V4
V1 < V1 && V4 <= V4
V1 < V1 or V1 < V1
V1 < V1 or V1 < V2
V1 < V1 or V1 < V3
V1 < V1 or V1 < V4
V1 < V1 or V1 <= V1
V1 < V1 or V1 <= V2
V1 < V1 or V1 <= V3
V1 < V1 or V1 <= V4
V1 < V1 or V1 == V1
V1 < V1 or V1 == V2
V1 < V1 or V1 == V3
V1 < V1 or V1 == V4
V1 < V1 or V1 != V1
V1 < V1 or V1 != V2
V1 < V1 or V1 != V3
V1 < V1 or V1 != V4
V1 < V1 or V1 < V1
V1 < V1 or V2 < V1
V1 < V1 or V3 < V1
V1 < V1 or V4 < V1
V1 < V1 or V1 <= V1
V1 < V1 or V2 <= V1
V1 < V1 or V3 <= V1
V1 < V1 or V4 <= V1
V1 < V1 or V2 < V1
V1 < V1 or V2 < V2
V1 < V1 or V2 < V3
V1 < V1 or V2 < V4
V1 < V1 or V2 <= V1
V1 < V1 or V2 <= V2
V1 < V1 or V2 <= V3
V1 < V1 or V2 <= V4
V1 < V1 or V2 == V1
V1 < V1 or V2 == V2
V1 < V1 or V2 == V3
V1 < V1 or V2 == V4
V1 < V1 or V2 != V1
V1 < V1 or V2 != V2
V1 < V1 or V2 != V3
V1 < V1 or V2 != V4
V1 < V1 or V1 < V2
V1 < V1 or V2 < V2
V1 < V1 or V3 < V2
V1 < V1 or V4 < V2
V1 < V1 or V1 <= V2
V1 < V1 or V2 <= V2
V1 < V1 or V3 <= V2
V1 < V1 or V4 <= V2
V1 < V1 or V3 < V1
V1 < V1 or V3 < V2
V1 < V1 or V3 < V3
V1 < V1 or V3 < V4
V1 < V1 or V3 <= V1
V1 < V1 or V3 <= V2
V1 < V1 or V3 <= V3
V1 < V1 or V3 <= V4
V1 < V1 or V3 == V1
V1 < V1 or V3 == V2
V1 < V1 or V3 == V3
V1 < V1 or V3 == V4
V1 < V1 or V3 != V1
V1 < V1 or V3 != V2
V1 < V1 or V3 != V3
V1 < V1 or V3 != V4
V1 < V1 or V1 < V3
V1 < V1 or V2 < V3
V1 < V1 or V3 < V3
V1 < V1 or V4 < V3
V1 < V1 or V1 <= V3
V1 < V1 or V2 <= V3
V1 < V1 or V3 <= V3
V1 < V1 or V4 <= V3
V1 < V1 or V4 < V1
V1 < V1 or V4 < V2
V1 < V1 or V4 < V3
V1 < V1 or V4 < V4
V1 < V1 or V4 <= V1
V1 < V1 or V4 <= V2
V1 < V1 or V4 <= V3
V1 < V1 or V4 <= V4
V1 < V1 or V4 == V1
V1 < V1 or V4 == V2
V1 < V1 or V4 == V3
V1 < V1 or V4 == V4
V1 < V1 or V4 != V1
V1 < V1 or V4 != V2
V1 < V1 or V4 != V3
V1 < V1 or V4 != V4
V1 < V1 or V1 < V4
V1 < V1 or V2 < V4
V1 < V1 or V3 < V4
V1 < V1 or V4 < V4
V1 < V1 or V1 <= V4
V1 < V1 or V2 <= V4
V1 < V1 or V3 <= V4
V1 < V1 or V4 <= V4

192
1 * 1 * 1 * 2 * 4 * 6 * 4
Luego variarían las cosas que están en la izquierda, o sea, así debería ser:
4 * 6 * 4 * 2 * 4 * 6 * 4

Luego se agregarían partes, como ya se ha visto.
V1 < V1 && V1 < V1 or V1 < V1
V1 < V1 && V1 < V1 or V1 < V2
V1 < V1 && V1 < V1 or V1 < V3
etc.
6 * 6 * 6 * 2 * 6 * 6 * 6 * 2 * 6 * 6 * 6

NOTA: Luego del símbolo "!=" viene ">" y luego "=>" pero yo los invertí ("<" y "<=") y también al orden de las variables. Puede ser confuso a la vista pero no hay problema con eso.

Esto es lo que obtuve:
Citar
V1 < V1
(ok)
V2 <= V2
V1 < V1 && V1 < V1
(ok)
V1 < V1 && V4 <= V4
V1 < V1 or V1 < V1
V1 < V2 or V1 < V1
V1 < V3 or V1 < V1
V1 < V4 or V1 < V1
(eso está mal)
V4 <= V4 or V1 < V1
V1 < V1 && V1 < V1 or V1 < V1
(esto está mal también)
El 1er error es que se salteó las combinaciones
V1 < V2 && V1 < V1
V1 < V3 && V1 < V1
V1 < V4 && V1 < V1
O sea, es como si hubiera hecho
1111464
1112111
1122111
1132111
1142111
o sea... en el 1er número, desde el 2 todo estaba al máximo, como si fuese
1119999
pero en vez de hacer
1112111
1112112
1112113
1112114
aumentó las cosas de la izquierda.

El 2ndo error es que pasó de
4642111
a
11111112111

Es horroroso. Es más o menos como si hubiese hecho
9999111
10090000
O sea se salteó cosas y no reseteó un número. Son 2 errores. Debería ser
4642464
11111111111

Este es el código (action script de Macromedia Flash 5 if that really matters)
Código:
Escena 1
   actions for fotograma 1
      // Subcondiciones en la condición.
      SCs = 1;
      // Valores de las partes de la SC.
      SC1P1 = 1;
      SC1P2 = 1;
      SC1P3 = 0;
      // Cosas para evitar ifs.
      Op1 = " < ";
      Op2 = " <= ";
      Op3 = " == ";
      Op4 = " != ";
      Op5 = " > ";
      Op6 = " => ";
      Rel1 = " && ";
      Rel2 = " or ";
      Cursor1 = 1;
      Cursor2 = 3;
      function PrintCond () {
         Cursor3 = 1;
         Print = "";
         while (Cursor3<SCs) {
            if (eval("SC"+Cursor3+"P2")<5) {
               Print = "V"+eval("SC"+Cursor3+"P1")+eval("Op"+eval("SC"+Cursor3+"P2"))+"V"+eval("SC"+Cursor3+"P3")+eval("Rel"+eval("SC"+Cursor3+"P4"))+Print;
            } else {
               Print = "V"+eval("SC"+Cursor3+"P3")+eval("Op"+(eval("SC"+Cursor3+"P2")-4))+"V"+eval("SC"+Cursor3+"P1")+eval("Rel"+eval("SC"+Cursor3+"P4"))+Print;
            }
            Cursor3 = Cursor3+1;
         }
         if (eval("SC"+Cursor3+"P2")<5) {
            Print = Print+"V"+eval("SC"+Cursor3+"P1")+eval("Op"+eval("SC"+Cursor3+"P2"))+"V"+eval("SC"+Cursor3+"P3");
         } else {
            Print = Print+"V"+eval("SC"+Cursor3+"P3")+eval("Op"+(eval("SC"+Cursor3+"P2")-4))+"V"+eval("SC"+Cursor3+"P1");
         }
         trace (Print);
      }
   actions for fotograma 2
      if (Cursor2 == 1 or Cursor2 == 3) {
         MaxValor = SCs*2;
      } else if (Cursor2 == 2) {
         MaxValor = 6;
      } else {
         MaxValor = 2;
      }
      if (eval("SC"+Cursor1+"P"+Cursor2)<MaxValor) {
         set ("SC"+Cursor1+"P"+Cursor2, eval("SC"+Cursor1+"P"+Cursor2)+1);
         PrintCond();
         Cursor2 = 3;
      } else {
         set ("SC"+Cursor1+"P"+Cursor2, 1);
         if (Cursor2>1) {
            Cursor2 = Cursor2-1;
         } else if (Cursor1>1) {
            Cursor1 = Cursor1-1;
            Cursor2 = 4;
         } else {
            set ("SC"+SCs+"P4", 1);
            SCs = SCs+1;
            Cursor1 = SCs;
            Cursor2 = 3;
            set ("SC"+SCs+"P1", 1);
            set ("SC"+SCs+"P2", 1);
            set ("SC"+SCs+"P3", 1);
            PrintCond();
         }
      }
   actions for fotograma 3
      gotoAndPlay (2);
Lo voy a revisar pero si alguien ve fácil cómo corregirlo, bien por él. Y si me dice acá pronto cómo se haría dicha corrección, buenísimo.


Título: Re: (Resuelto): Errores en generador de sentencias condicionales.
Publicado por: Tachikomaia en 19 Agosto 2018, 02:16 am
Faltaba esto:
Cursor1 = SCs;
en el 2ndo fotograma, o sea acá:
Código:
      if (eval("SC"+Cursor1+"P"+Cursor2)<MaxValor) {
         set ("SC"+Cursor1+"P"+Cursor2, eval("SC"+Cursor1+"P"+Cursor2)+1);
         PrintCond();
         ACÁAAAAAAAAAAAAAAAAAAAA Cursor1 = SCs;
         Cursor2 = 3;
Con eso se marca que el valor a modificarse será el de la última subcondición (la que esté más a la derecha).

Y en el while del fotograma 1 había que poner Print al inicio en vez de al final:
Código:
         while (Cursor3<SCs) {
            if (eval("SC"+Cursor3+"P2")<5) {
               Print = "V"+eval("SC"+Cursor3+"P1")+eval("Op"+eval("SC"+Cursor3+"P2"))+"V"+eval("SC"+Cursor3+"P3")+eval("Rel"+eval("SC"+Cursor3+"P4"))+Print;
            } else {
               Print = "V"+eval("SC"+Cursor3+"P3")+eval("Op"+(eval("SC"+Cursor3+"P2")-4))+"V"+eval("SC"+Cursor3+"P1")+eval("Rel"+eval("SC"+Cursor3+"P4"))+Print;
            }
            Cursor3 = Cursor3+1;
         }

O sea quedaría así:
Print =  Print + "V"+eval("SC"+Cursor3+"P1")+eval("Op"+eval("SC"+Cursor3+"P2"))+"V"+eval("SC"+Cursor3+"P3")+eval("Rel"+eval("SC"+Cursor3+"P4"));
Y:
Print = Print + "V"+eval("SC"+Cursor3+"P3")+eval("Op"+(eval("SC"+Cursor3+"P2")-4))+"V"+eval("SC"+Cursor3+"P1")+eval("Rel"+eval("SC"+Cursor3+"P4"));

Les dejo una versión simplificada, o sea, esta usa los 6 símbolos en vez de 4 e invertir. La diferencia es que no hay ifs en la función PrintCond.
Código:
Escena 1
   actions for fotograma 1
      // Subcondiciones en la condición.
      SCs = 1;
      // Valores de las partes de la SC.
      SC1P1 = 1;
      SC1P2 = 1;
      SC1P3 = 0;
      // Cosas para evitar ifs.
      Op1 = " < ";
      Op2 = " <= ";
      Op3 = " == ";
      Op4 = " != ";
      Op5 = " => ";
      Op6 = " > ";
      Rel1 = " && ";
      Rel2 = " or ";
      Cursor1 = 1;
      Cursor2 = 3;
      function PrintCond () {
         Cursor3 = 1;
         Print = "";
         while (Cursor3<SCs) {
            Print = Print+"V"+eval("SC"+Cursor3+"P1")+eval("Op"+eval("SC"+Cursor3+"P2"))+"V"+eval("SC"+Cursor3+"P3")+eval("Rel"+eval("SC"+Cursor3+"P4"));
            Cursor3 = Cursor3+1;
         }
         // Eso traduce los valores en variables o símbolos y los va concatenando.
         Print = Print+"V"+eval("SC"+Cursor3+"P1")+eval("Op"+eval("SC"+Cursor3+"P2"))+"V"+eval("SC"+Cursor3+"P3");
         // Eso es la subcondición final, la que no tiene parte 4 ("&&" o "or").
         trace (Print);
      }
   actions for fotograma 2
      if (Cursor2 == 1 or Cursor2 == 3) {
         MaxValor = SCs*2;
      } else if (Cursor2 == 2) {
         MaxValor = 6;
      } else {
         MaxValor = 2;
      }
      // Máximo valor de la parte donde esté el cursor 2. Si por ejemplo es la parte 2 su máximo valor es 6, o sea los 6 posibles operadores.
      if (eval("SC"+Cursor1+"P"+Cursor2)<MaxValor) {
         // Si el valor señalado puede aumentar.
         set ("SC"+Cursor1+"P"+Cursor2, eval("SC"+Cursor1+"P"+Cursor2)+1);
         PrintCond();
         Cursor1 = SCs;
         Cursor2 = 3;
         // Aumenta, se muestra y se resetean los cursores.
      } else {
         // El valor se resetea.
         set ("SC"+Cursor1+"P"+Cursor2, 1);
         if (Cursor2>1) {
            // Si el cursor 2 puede retroceder, o sea marcar una parte más en la izquierda, se reduce.
            Cursor2 = Cursor2-1;
         } else if (Cursor1>1) {
            // Sino, si el cursor 1 puede retroceder, se reduce. El cursor 1 marca la subcondición y la el 2 marca la parte (variable1, operador, variable2, relación. En vez de operador debería decir comparador, no me di cuenta). Y el cursor 2 se queda al máximo (marcando la parte más a la derecha de la subcondición, la relación "&&" o "or").
            Cursor1 = Cursor1-1;
            Cursor2 = 4;
         } else {
            // Sino, se crea la parte relación o 4 de la última subcondición (derecha), aumenta la cantidad de subcondiciones, los cursores quedan al máximo (en la derecha), se crea una nueva subcondición, de 3 partes, y se muestra todo.
            set ("SC"+SCs+"P4", 1);
            SCs = SCs+1;
            Cursor1 = SCs;
            Cursor2 = 3;
            set ("SC"+SCs+"P1", 1);
            set ("SC"+SCs+"P2", 1);
            set ("SC"+SCs+"P3", 1);
            PrintCond();
         }
      }
   actions for fotograma 3
      gotoAndPlay (2);
La cantidad de condiciones que muestra es abrumadora. Aunque claro muchas son repetidas y son simplonas. Por algo se empieza...

Aquí he reducido el número de posibles valores. O sea, con 2 subcondiciones son
4*6*4*2*4*6*4
que según calculé son 9216 posibilidades (con repeticiones y chorradas, luego las intentaré evitar).
Pero en esta versión es
2*2*2*2*2*2*2
Así es el resultado:
[spoiler]V1 < V1
V1 < V2
V1 <= V1
V1 <= V2
V2 < V1
V2 < V2
V2 <= V1
V2 <= V2
V1 < V1 && V1 < V1
V1 < V1 && V1 < V2
V1 < V1 && V1 <= V1
V1 < V1 && V1 <= V2
V1 < V1 && V2 < V1
V1 < V1 && V2 < V2
V1 < V1 && V2 <= V1
V1 < V1 && V2 <= V2
V1 < V1 or V1 < V1
V1 < V1 or V1 < V2
V1 < V1 or V1 <= V1
V1 < V1 or V1 <= V2
V1 < V1 or V2 < V1
V1 < V1 or V2 < V2
V1 < V1 or V2 <= V1
V1 < V1 or V2 <= V2
V1 < V2 && V1 < V1
V1 < V2 && V1 < V2
V1 < V2 && V1 <= V1
V1 < V2 && V1 <= V2
V1 < V2 && V2 < V1
V1 < V2 && V2 < V2
V1 < V2 && V2 <= V1
V1 < V2 && V2 <= V2
V1 < V2 or V1 < V1
V1 < V2 or V1 < V2
V1 < V2 or V1 <= V1
V1 < V2 or V1 <= V2
V1 < V2 or V2 < V1
V1 < V2 or V2 < V2
V1 < V2 or V2 <= V1
V1 < V2 or V2 <= V2
V1 <= V1 && V1 < V1
V1 <= V1 && V1 < V2
V1 <= V1 && V1 <= V1
V1 <= V1 && V1 <= V2
V1 <= V1 && V2 < V1
V1 <= V1 && V2 < V2
V1 <= V1 && V2 <= V1
V1 <= V1 && V2 <= V2
V1 <= V1 or V1 < V1
V1 <= V1 or V1 < V2
V1 <= V1 or V1 <= V1
V1 <= V1 or V1 <= V2
V1 <= V1 or V2 < V1
V1 <= V1 or V2 < V2
V1 <= V1 or V2 <= V1
V1 <= V1 or V2 <= V2
V1 <= V2 && V1 < V1
V1 <= V2 && V1 < V2
V1 <= V2 && V1 <= V1
V1 <= V2 && V1 <= V2
V1 <= V2 && V2 < V1
V1 <= V2 && V2 < V2
V1 <= V2 && V2 <= V1
V1 <= V2 && V2 <= V2
V1 <= V2 or V1 < V1
V1 <= V2 or V1 < V2
V1 <= V2 or V1 <= V1
V1 <= V2 or V1 <= V2
V1 <= V2 or V2 < V1
V1 <= V2 or V2 < V2
V1 <= V2 or V2 <= V1
V1 <= V2 or V2 <= V2
V2 < V1 && V1 < V1
V2 < V1 && V1 < V2
V2 < V1 && V1 <= V1
V2 < V1 && V1 <= V2
V2 < V1 && V2 < V1
V2 < V1 && V2 < V2
V2 < V1 && V2 <= V1
V2 < V1 && V2 <= V2
V2 < V1 or V1 < V1
V2 < V1 or V1 < V2
V2 < V1 or V1 <= V1
V2 < V1 or V1 <= V2
V2 < V1 or V2 < V1
V2 < V1 or V2 < V2
V2 < V1 or V2 <= V1
V2 < V1 or V2 <= V2
V2 < V2 && V1 < V1
V2 < V2 && V1 < V2
V2 < V2 && V1 <= V1
V2 < V2 && V1 <= V2
V2 < V2 && V2 < V1
V2 < V2 && V2 < V2
V2 < V2 && V2 <= V1
V2 < V2 && V2 <= V2
V2 < V2 or V1 < V1
V2 < V2 or V1 < V2
V2 < V2 or V1 <= V1
V2 < V2 or V1 <= V2
V2 < V2 or V2 < V1
V2 < V2 or V2 < V2
V2 < V2 or V2 <= V1
V2 < V2 or V2 <= V2
V2 <= V1 && V1 < V1
V2 <= V1 && V1 < V2
V2 <= V1 && V1 <= V1
V2 <= V1 && V1 <= V2
V2 <= V1 && V2 < V1
V2 <= V1 && V2 < V2
V2 <= V1 && V2 <= V1
V2 <= V1 && V2 <= V2
V2 <= V1 or V1 < V1
V2 <= V1 or V1 < V2
V2 <= V1 or V1 <= V1
V2 <= V1 or V1 <= V2
V2 <= V1 or V2 < V1
V2 <= V1 or V2 < V2
V2 <= V1 or V2 <= V1
V2 <= V1 or V2 <= V2
V2 <= V2 && V1 < V1
V2 <= V2 && V1 < V2
V2 <= V2 && V1 <= V1
V2 <= V2 && V1 <= V2
V2 <= V2 && V2 < V1
V2 <= V2 && V2 < V2
V2 <= V2 && V2 <= V1
V2 <= V2 && V2 <= V2
V2 <= V2 or V1 < V1
V2 <= V2 or V1 < V2
V2 <= V2 or V1 <= V1
V2 <= V2 or V1 <= V2
V2 <= V2 or V2 < V1
V2 <= V2 or V2 < V2
V2 <= V2 or V2 <= V1
V2 <= V2 or V2 <= V2
V1 < V1 && V1 < V1 && V1 < V1
V1 < V1 && V1 < V1 && V1 < V2
V1 < V1 && V1 < V1 && V1 <= V1
V1 < V1 && V1 < V1 && V1 <= V2
[/spoiler] Y sigue. ¿Errores? Si no aviso, es que no veo.