Skip to main content
added 2 characters in body
Source Link
RunnyKine
  • 33.3k
  • 3
  • 110
  • 176

Another way:

Module[{i = 0, l = #, f},
   
   f["x"]f[x_String] := Symbol["x"Symbol[x <> ToString[++i]];
    f[x_] := x;
    Map[f, l, {2}] ]& @]] list&@list
{{0, x1, x2, 0}, {0, x3, x4, x5}, {0, x6, x7, x8}, {x9, x10, x11, x12},
 {x13, x14, x15, x16}, {x17, x18, x19, x20}, {x21, x22, x23, x24},
 {x25, x26, x27, x28}, {0, x29, x30, x31}}

Another way:

Module[{i = 0, l = #},
     f["x"] := Symbol["x" <> ToString[++i]];
    f[x_] := x;
    Map[f, l, {2}] ]& @ list
{{0, x1, x2, 0}, {0, x3, x4, x5}, {0, x6, x7, x8}, {x9, x10, x11, x12},
 {x13, x14, x15, x16}, {x17, x18, x19, x20}, {x21, x22, x23, x24},
 {x25, x26, x27, x28}, {0, x29, x30, x31}}

Another way:

Module[{i = 0, l = #, f},  
   f[x_String] := Symbol[x <> ToString[++i]];
   f[x_] := x;
   Map[f, l, {2}]] &@list
{{0, x1, x2, 0}, {0, x3, x4, x5}, {0, x6, x7, x8}, {x9, x10, x11, x12},
 {x13, x14, x15, x16}, {x17, x18, x19, x20}, {x21, x22, x23, x24},
 {x25, x26, x27, x28}, {0, x29, x30, x31}}
Source Link
RunnyKine
  • 33.3k
  • 3
  • 110
  • 176

Another way:

Module[{i = 0, l = #},
    f["x"] := Symbol["x" <> ToString[++i]];
    f[x_] := x;
    Map[f, l, {2}] ]& @ list
{{0, x1, x2, 0}, {0, x3, x4, x5}, {0, x6, x7, x8}, {x9, x10, x11, x12},
 {x13, x14, x15, x16}, {x17, x18, x19, x20}, {x21, x22, x23, x24},
 {x25, x26, x27, x28}, {0, x29, x30, x31}}