• API
• FAQ
• Tools
• Archive
daily pastebin goal
50%
SHARE
TWEET

# Untitled

a guest Nov 21st, 2017 79 Never
ENDING IN00days00hours00mins00secs
1. Ejercicio1[M_] := Module[{i, j, pref, pal, fin}, fin = {{}};
2.   For[i = 1, i <= Length[M], i++, pal = M[[i]];
3.    For[j = 1, j <= Length[pal], j++, pref = Take[pal, {1, j}];
4.     fin = Append[fin, pref];];];
5.   Return[Union[fin]]]
6.
7. Ejercicio2[M_] := Module[{fin, pal, suf, j, i}, fin = {{}};
8.   For[i = 1, i <= Length[M], i++, pal = M[[i]];
9.    For[j = 1, j <= Length[pal], j++, suf = Take[pal, {j, Length[pal]}];
10.     fin = Append[fin, suf];];];
11.   Return[Union[fin]]]
12.
13. Ejercicio3[M_] :=
14.   Module[{Q, q0, F, d, alf, i, j, aux, x}, Q = Ejercicio1[M];
15.    alf = Union[Flatten[M]];
16.    q0 = {};
17.    F = M;
18.    d = {};
19.    For[i = 1, i <= Length[Q], i++,
20.     aux = Q[[i]
21.       ];
22.     For[j = 1, j <= Length[alf], j++,
23.      x = Append[aux, alf[[j]]
24.        ];
25.      If[MemberQ[Q, x], AppendTo[d, {aux, alf[[j]], x}]
26.       ];
27.      ];
28.     ];
29.    Return[{Q, alf, d, q0, F}]
30.    ];
31.
32. Ejercicio4[M_] :=
33.   Module[{Q, q0, F, d, alf, i, j, aux, x}, Q = Ejercicio1[M];
34.    alf = Union[Flatten[M]];
35.    q0 = {};
36.    F = M;
37.    d = {};
38.    For[k = 1, k <= Length[alf], k++,
39.     AppendTo[d, {q0, alf[[k]], q0}];
40.     ];
41.    For[i = 1, i <= Length[Q], i++, aux = Q[[i]];
42.     For[j = 1, j <= Length[alf], j++,
43.      x = Append[aux, alf[[j]]
44.        ];
45.      If[MemberQ[Q, x],
46.       AppendTo[d, {aux, alf[[j]], x}]
47.       ];
48.      ];
49.     ];
50.    Return[{Q, alf, d, q0, F}]
51.    ];
52.
53. Ejercicio5[w_, A_] := Module[{estados, nEstados, i, j, k, trans},
54.    estados = {A[[4]]};
55.    For[i = 1, i <= Length[w], i++,
56.     nEstados = {};
57.     For[j = 1, j <= Length[estados], j++,
58.      trans = Cases[A[[3]], {estados[[j]], w[[i]], _}];
59.      For[k = 1, k <= Length[trans], k++,
60.       AppendTo[nEstados, trans[[k, 3]]];];
61.      ];
63.     ];
64.    Return[Intersection[estados, A[[5]]] != {}];
65.    ];
66.
67. Ejercicio6[M_, x_] :=
68.   Module[{A, estados, nEstados, i, j, k, trans, pos},
69.    pos = {};
70.    A = Ejercicio3[M];
71.    estados = {};
72.    For[i = 1, i <= Length[x], i++,
73.     AppendTo[estados, {A[[4]], 0}];
74.     nEstados = {};
75.     For[j = 1, j <= Length[estados], j++,
76.      trans = Cases[A[[3]], {estados[[j, 1]], x[[i]], _}];
77.      For[k = 1, k <= Length[trans], k++,
78.       AppendTo[nEstados, {trans[[k, 3]], estados[[j, 2]] + 1}];];
79.      ];