Advertisement
rsvaco

MATHEMATICA TAL PRACT 3

Nov 15th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. Ejercicio1[palabras_] := Module[{i, j, res, aux},
  2. res = {{}};
  3. For[i = 1, i <= Length[palabras], i++,
  4. aux = palabras[[i]];
  5. For[j = 1, j <= Length[aux], j++,
  6. AppendTo[res, Take[aux, j]];
  7. ];
  8. ];
  9. Return[res]
  10. ];
  11.  
  12.  
  13. Ejercicio2[palabras_] := Module[{i, j, res, aux},
  14. res = {{}};
  15. For[i = 1, i <= Length[palabras], i++,
  16. aux = palabras[[i]];
  17. For[j = 1, j <= Length[aux], j++,
  18. AppendTo[res, Take[aux, -j]];
  19. ];
  20. ];
  21. Return[res]
  22. ];
  23.  
  24.  
  25. Ejercicio3[palabras_] :=
  26. Module[{i, j, res, prefijos, alf, trans, boolTrans},
  27. prefijos = Ejercicio1[palabras];
  28. alf = {};
  29.  
  30. For[i = 1, i <= Length[palabras], i++,
  31. For[j = 1, j <= Length[palabras[[i]]], j++,
  32. alf = Append[alf, palabras[[i]][[j]]];
  33. ];
  34. ];
  35.  
  36. alf = DeleteDuplicates[alf];
  37. (*Print[alf];*)
  38. trans = {};
  39.  
  40. For[i = 1, i <= Length[alf], i++,
  41. If[ContainsAny[prefijos, {{alf[[i]]}}],
  42. AppendTo[trans, {{}, alf[[i]], {alf[[i]]}}];
  43. ];
  44. ];
  45.  
  46. (*Print[prefijos];*)
  47. res = {prefijos, alf, {}, {}, palabras};
  48. For[i = 0, i < Length[prefijos], i++,
  49. For[j = 0, j < Length[prefijos[[i]]], j++,
  50. boolTrans = (Length[prefijos[[i]]] ==
  51. Length[prefijos[[i + 1]]] - 1);
  52. ];
  53. If[boolTrans,
  54. AppendTo[
  55. trans, {prefijos[[i]], Last[prefijos[[i + 1]]],
  56. prefijos[[i + 1]]}];
  57. ];
  58. ];
  59. (*Print[trans];*)
  60. res[[3]] = trans;
  61. res[[2]] = alf;
  62. Return[res];
  63. ];
  64.  
  65. Ejercicio4[palabras_] := Module[{af, i, aux},
  66. af = Ejercicio3[palabras];
  67. aux = {};
  68.  
  69. For[i = 1, i <= Length[af[[2]]], i++,
  70. AppendTo[aux, {{}, af[[2]][[i]], {}}];
  71. ];
  72. af[[3]] = Join[aux, af[[3]]];
  73. Return[af];
  74. ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement