Skip to content

Instantly share code, notes, and snippets.

@cristianmiranda
Created October 8, 2017 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristianmiranda/0434b51bb7d02b43701795a8953dd630 to your computer and use it in GitHub Desktop.
Save cristianmiranda/0434b51bb7d02b43701795a8953dd630 to your computer and use it in GitHub Desktop.
RPN - && ||
if (a == 10 && b >= 30) {
y = y + 1;
} else {
y = y - 1;
}
1 - a
2 - 10
3 - CMP
4 - BNE
5 - 19
7 - b
8 - 30
9 - CMP
10 - BLT
11 - 19
12 - y
13 - y
14 - 1
15 - +
16 - =
17 - BI
18 - 24
19 - y
20 - y
21 - 1
22 - -
23 - =
24 -
############################################################
############################################################
############################################################
if (x < y || x < z) {
y = y + 1;
}
1 - x
2 - y
3 - CMP
4 - BLT
5 - 14
7 - x
8 - z
9 - CMP
10 - BLT
11 - 14
12 - BI
13 - 19
14 - y
15 - y
16 - 1
17 - +
18 - =
19 -
############################################################
############################################################
############################################################
if (a == 10 && b >= 30) {
y = y + 1;
} else {
if (x < 10 || a == 20) {
y = 1;
} else {
y = y - 1;
}
}
1 - a
2 - 10
3 - CMP
4 - BNE
5 - 19
7 - b
8 - 30
9 - CMP
10 - BLT
11 - 19
12 - y
13 - y
14 - 1
15 - +
16 - =
17 - BI
18 - 39
19 - x
20 - 10
21 - CMP
22 - BLT
23 - 31
24 - a
25 - 20
26 - CMP
27 - BEQ
28 - 31
29 - BI
30 - 34
31 - y
32 - 1
33 - =
34 - y
35 - y
36 - 1
37 - -
38 - =
39 -
############################################################
############################################################
############################################################
if (x == z && x < y || x < z) {
y = 1;
}
1 - x
2 - z
3 - CMP
4 - BNE
5 - 12
7 - x
8 - y
9 - CMP
10 - BLT
11 - 17
12 - x
13 - z
14 - CMP
15 - BGE
16 - 20
17 - y
18 - 1
19 - =
20 -
@ezequielmrobles
Copy link

Cris, todo bien?
Haciendo las Polacas vemos que coincidimos en casi todo. Fijate que te salteaste la numeración de las posiciones y no pusiste la posición 6, después todo joya.
Respecto a la polaca 2 y la polaca 3, hicimos el segundo salto del OR distinto:

  • Polaca 2: Yo lo pensé con BGE y yendo al final del programa, sino sigue de largo (sin el BI).
  • Polaca 3: Yo lo pensé con BNE y yendo al else, sino sigue (sin el BI).
  • Polaca 3: Fijate que te faltó el último salto BI después del "Y 1 =", Sino te va ejecutar el último ELSE también.

Fijate y lo vemos así nos corregimos.
Abrazo.
polacascris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment