Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ejercicio1[palabras_] := Module[{i, j, res, aux},
- res = {{}};
- For[i = 1, i <= Length[palabras], i++,
- aux = palabras[[i]];
- For[j = 1, j <= Length[aux], j++,
- AppendTo[res, Take[aux, j]];
- ];
- ];
- Return[res]
- ];
- Ejercicio2[palabras_] := Module[{i, j, res, aux},
- res = {{}};
- For[i = 1, i <= Length[palabras], i++,
- aux = palabras[[i]];
- For[j = 1, j <= Length[aux], j++,
- AppendTo[res, Take[aux, -j]];
- ];
- ];
- Return[res]
- ];
- Ejercicio3[palabras_] :=
- Module[{i, j, res, prefijos, alf, trans, boolTrans},
- prefijos = Ejercicio1[palabras];
- alf = {};
- For[i = 1, i <= Length[palabras], i++,
- For[j = 1, j <= Length[palabras[[i]]], j++,
- alf = Append[alf, palabras[[i]][[j]]];
- ];
- ];
- alf = DeleteDuplicates[alf];
- (*Print[alf];*)
- trans = {};
- For[i = 1, i <= Length[alf], i++,
- If[ContainsAny[prefijos, {{alf[[i]]}}],
- AppendTo[trans, {{}, alf[[i]], {alf[[i]]}}];
- ];
- ];
- (*Print[prefijos];*)
- res = {prefijos, alf, {}, {}, palabras};
- For[i = 0, i < Length[prefijos], i++,
- For[j = 0, j < Length[prefijos[[i]]], j++,
- boolTrans = (Length[prefijos[[i]]] ==
- Length[prefijos[[i + 1]]] - 1);
- ];
- If[boolTrans,
- AppendTo[
- trans, {prefijos[[i]], Last[prefijos[[i + 1]]],
- prefijos[[i + 1]]}];
- ];
- ];
- (*Print[trans];*)
- res[[3]] = trans;
- res[[2]] = alf;
- Return[res];
- ];
- Ejercicio4[palabras_] := Module[{af, i, aux},
- af = Ejercicio3[palabras];
- aux = {};
- For[i = 1, i <= Length[af[[2]]], i++,
- AppendTo[aux, {{}, af[[2]][[i]], {}}];
- ];
- af[[3]] = Join[aux, af[[3]]];
- Return[af];
- ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement