Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.51 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Strings form list to function
  2. mx = {};
  3. arg = {};
  4. fun = {};
  5. x =.
  6. y =.
  7.        
  8. switchfunction2[y_] := Switch[y,
  9.   1, AppendTo[fun, Cos[Random[Integer, {1, 10}]]],
  10.   2, AppendTo[fun, Sin[Random[Integer, {1, 10}]]],
  11.   3, AppendTo[fun, Tan[Random[Integer, {1, 10}]]],
  12.   4, AppendTo[fun, Csc[Random[Integer, {1, 10}]]],
  13.   5, AppendTo[fun, Sec[Random[Integer, {1, 10}]]],
  14.   6, AppendTo[fun, Cot[Random[Integer, {1, 10}]]]
  15. ]
  16.        
  17. Do[AppendTo[mx, Random[Integer, {1, 10}]], {i, 2}]
  18.  
  19. mx[[1]] " has been chosed"
  20. mx[[2]] "argumments "
  21. Do[AppendTo[arg, Random[Integer, {1, 5}]], {i, mx[[2]]}]
  22. arg
  23. Do[switchfunction2 /@ {arg[[i]]}, {i, mx[[2]]}]
  24. fun
  25.        
  26. mx = RandomInteger[{1, 10}, 2];
  27. arg = RandomInteger[{1, 5}, mx[[2]]];
  28.  
  29. switch[y_] := Module[{f},
  30.   f = Switch[y, 1, Cos, 2, Sin, 3, Tan, 4, Csc, 5, Sec, 6, Cot];
  31.   f[RandomInteger[{1, 10}]]]
  32.  
  33. fun = switch /@ arg;
  34.  
  35. Total[fun]
  36.        
  37. mx = RandomInteger[{1, 10}, 2]
  38. flist = RandomChoice[{Cos, Sin, Tan, Csc, Sec, Cot}, mx[[2]]];
  39.  
  40. fun = #[RandomInteger[{1, 10}]] & /@ flist;
  41. Total[fun]
  42.        
  43. mx = Table[Random[Integer, {1, 10}], {2}];
  44. arg = Table[Random[Integer, {1, 5}], {mx[[2]]}];
  45.  
  46. switch[y_] := Module[{f},
  47.   f = Switch[y, 1, Cos, 2, Sin, 3, Tan, 4, Csc, 5, Sec, 6, Cot];
  48.   f[Random[Integer, {1, 10}]]]
  49.  
  50. fun = switch /@ arg;
  51.  
  52. Total[fun]
  53.        
  54. f := Module[{mx, arg, switch},
  55.   mx = Random[Integer, {1, 10}];
  56.   arg = Table[Random[Integer, {1, 5}], {mx}];
  57.   switch[y_] := Module[{f},
  58.     f = Switch[y, 1, Cos, 2, Sin, 3, Tan, 4, Csc, 5, Sec, 6, Cot];
  59.     f[Random[Integer, {1, 10}]]];
  60.   Total[switch /@ arg]]