Skip to main content
added 130 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

Or ...

Using ConstantArray:

 mat0 := Most@Flatten[#, 1] & /@ 
 ({#, .25 + #} & /@ ConstantArray[#, Ceiling[(Length@#)/2]]&@
 Range[0, #, .5] &) ;
 [email protected]
 (* gives *)

{{0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}}

Using Table:

 mat2:=Most@Flatten[#, 1] & /@ (Transpose /@ 
  Table[{#, .25 + #} & /@ #, {Ceiling[(Length@#1)/2]}] &@ Range[0, #, .5] &)

Using NestList:

 mat3:=Most@Flatten[#, 1] & /@ 
(NestList[Join, {#1, #2}, Floor[(Length@#1)/2]] & @@ {#, .25 + #} &
 @Range[0, #, .5] &)

Using Table again (less cluttered and more general):

 mat4:= Table[{#2, #1}[[1 + Mod[i, 2]]], {i, #3}] &;
 mat5 := Table[{#1, #2}[[1 + Mod[i, 2]]], {i, 0, #3 - 1}] &;
 mat4[{a, b, c, d}, {e, f, g}, 5]
 (* givesand  *)
 mat5[{a, b, c, d}, {e, f, g}, 5]
 (* both give *)
{{a, b, c, d}, {e, f, g}, {a, b, c, d}, {e, f, g}, {a, b, c, d}}

Or ...

Using ConstantArray:

 mat0 := Most@Flatten[#, 1] & /@ 
 ({#, .25 + #} & /@ ConstantArray[#, Ceiling[(Length@#)/2]]&@
 Range[0, #, .5] &) ;
 [email protected]
 (* gives *)

{{0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}}

Using Table:

 mat2:=Most@Flatten[#, 1] & /@ (Transpose /@ 
  Table[{#, .25 + #} & /@ #, {Ceiling[(Length@#1)/2]}] &@ Range[0, #, .5] &)

Using NestList:

 mat3:=Most@Flatten[#, 1] & /@ 
(NestList[Join, {#1, #2}, Floor[(Length@#1)/2]] & @@ {#, .25 + #} &
 @Range[0, #, .5] &)

Using Table again (less cluttered and more general):

 mat4:= Table[{#2, #1}[[1 + Mod[i, 2]]], {i, #3}] &;
 mat4[{a, b, c, d}, {e, f, g}, 5]
 (* gives *)
{{a, b, c, d}, {e, f, g}, {a, b, c, d}, {e, f, g}, {a, b, c, d}}

Or ...

Using ConstantArray:

 mat0 := Most@Flatten[#, 1] & /@ 
 ({#, .25 + #} & /@ ConstantArray[#, Ceiling[(Length@#)/2]]&@
 Range[0, #, .5] &) ;
 [email protected]
 (* gives *)

{{0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}}

Using Table:

 mat2:=Most@Flatten[#, 1] & /@ (Transpose /@ 
  Table[{#, .25 + #} & /@ #, {Ceiling[(Length@#1)/2]}] &@ Range[0, #, .5] &)

Using NestList:

 mat3:=Most@Flatten[#, 1] & /@ 
(NestList[Join, {#1, #2}, Floor[(Length@#1)/2]] & @@ {#, .25 + #} &
 @Range[0, #, .5] &)

Using Table again (less cluttered and more general):

 mat4:= Table[{#2, #1}[[1 + Mod[i, 2]]], {i, #3}] &;
 mat5 := Table[{#1, #2}[[1 + Mod[i, 2]]], {i, 0, #3 - 1}] &;
 mat4[{a, b, c, d}, {e, f, g}, 5]
 (* and  *)
 mat5[{a, b, c, d}, {e, f, g}, 5]
 (* both give *)
{{a, b, c, d}, {e, f, g}, {a, b, c, d}, {e, f, g}, {a, b, c, d}}
added 3 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

Or ...

Using ConstantArray:

 mat0 := Most@Flatten[#, 1] & /@ 
 ({#, .25 + #} & /@ ConstantArray[#, Ceiling[(Length@#)/2]&@2]]&@
 Range[0, #, .5] &) ;
 [email protected]
 (* gives *)

{{0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}}

Using Table:

 mat2:=Most@Flatten[#, 1] & /@ (Transpose /@ 
  Table[{#, .25 + #} & /@ #, {Ceiling[(Length@#1)/2]}] &@ Range[0, #, .5] &)

Using NestList:

 mat3:=Most@Flatten[#, 1] & /@ 
(NestList[Join, {#1, #2}, Floor[(Length@#1)/2]] & @@ {#, .25 + #} &
 @Range[0, #, .5] &)

Using Table again (less cluttered and more general):

 mat4:= Table[{#1#2, #2#1}[[1 + Mod[i, 2]]], {i, #3}] &;
 mat4[{a, b, c, d}, {e, f, g}, 5]
 (* gives *)
{{e, f, g}, {a, b, c, d}, {e, f, g}, {a, b, c, d}, {e, f, g}, {a, b, c, d}}

Or ...

Using ConstantArray:

 mat0 := Most@Flatten[#, 1] & /@ 
 ({#, .25 + #} & /@ ConstantArray[#, Ceiling[(Length@#)/2]&@
 Range[0, #, .5] &) ;
 [email protected]
 (* gives *)

{{0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}}

Using Table:

 mat2:=Most@Flatten[#, 1] & /@ (Transpose /@ 
  Table[{#, .25 + #} & /@ #, {Ceiling[(Length@#1)/2]}] &@ Range[0, #, .5] &)

Using NestList:

 mat3:=Most@Flatten[#, 1] & /@ 
(NestList[Join, {#1, #2}, Floor[(Length@#1)/2]] & @@ {#, .25 + #} &
 @Range[0, #, .5] &)

Using Table again (less cluttered and more general):

 mat4:= Table[{#1, #2}[[1 + Mod[i, 2]]], {i, #3}] &;
 mat4[{a, b, c, d}, {e, f, g}, 5]
 (* gives *)
{{e, f, g}, {a, b, c, d}, {e, f, g}, {a, b, c, d}, {e, f, g}}

Or ...

Using ConstantArray:

 mat0 := Most@Flatten[#, 1] & /@ 
 ({#, .25 + #} & /@ ConstantArray[#, Ceiling[(Length@#)/2]]&@
 Range[0, #, .5] &) ;
 [email protected]
 (* gives *)

{{0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}}

Using Table:

 mat2:=Most@Flatten[#, 1] & /@ (Transpose /@ 
  Table[{#, .25 + #} & /@ #, {Ceiling[(Length@#1)/2]}] &@ Range[0, #, .5] &)

Using NestList:

 mat3:=Most@Flatten[#, 1] & /@ 
(NestList[Join, {#1, #2}, Floor[(Length@#1)/2]] & @@ {#, .25 + #} &
 @Range[0, #, .5] &)

Using Table again (less cluttered and more general):

 mat4:= Table[{#2, #1}[[1 + Mod[i, 2]]], {i, #3}] &;
 mat4[{a, b, c, d}, {e, f, g}, 5]
 (* gives *)
{{a, b, c, d}, {e, f, g}, {a, b, c, d}, {e, f, g}, {a, b, c, d}}
added 243 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

Or ...

Using ConstantArray:

 mat0 := Most@Flatten[#, 1] & /@ 
 ({#, .25 + #} & /@ ConstantArray[#, Ceiling[(Length@#)/2]&@
 Range[0, #, .5] &) ;
 [email protected]
 (* gives *)

{{0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}}

Using Table:

 mat2:=Most@Flatten[#, 1] & /@ (Transpose /@ 
  Table[{#, .25 + #} & /@ #, {Ceiling[(Length@#1)/2]}] &@ Range[0, #, .5] &)

Using NestList:

 mat3:=Most@Flatten[#, 1] & /@ 
(NestList[Join, {#1, #2}, Floor[(Length@#1)/2]] & @@ {#, .25 + #} &
 @Range[0, #, .5] &)

Using Table again (less cluttered and more general):

 mat4:= Table[{#1, #2}[[1 + Mod[i, 2]]], {i, #3}] &;
 mat4[{a, b, c, d}, {e, f, g}, 5]
 (* gives *)
{{e, f, g}, {a, b, c, d}, {e, f, g}, {a, b, c, d}, {e, f, g}}

Or ...

Using ConstantArray:

 mat0 := Most@Flatten[#, 1] & /@ 
 ({#, .25 + #} & /@ ConstantArray[#, Ceiling[(Length@#)/2]&@
 Range[0, #, .5] &) ;
 [email protected]
 (* gives *)

{{0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}}

Using Table:

 mat2:=Most@Flatten[#, 1] & /@ (Transpose /@ 
  Table[{#, .25 + #} & /@ #, {Ceiling[(Length@#1)/2]}] &@ Range[0, #, .5] &)

Using NestList:

 mat3:=Most@Flatten[#, 1] & /@ 
(NestList[Join, {#1, #2}, Floor[(Length@#1)/2]] & @@ {#, .25 + #} &
 @Range[0, #, .5] &)

Or ...

Using ConstantArray:

 mat0 := Most@Flatten[#, 1] & /@ 
 ({#, .25 + #} & /@ ConstantArray[#, Ceiling[(Length@#)/2]&@
 Range[0, #, .5] &) ;
 [email protected]
 (* gives *)

{{0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5, 2.}}

Using Table:

 mat2:=Most@Flatten[#, 1] & /@ (Transpose /@ 
  Table[{#, .25 + #} & /@ #, {Ceiling[(Length@#1)/2]}] &@ Range[0, #, .5] &)

Using NestList:

 mat3:=Most@Flatten[#, 1] & /@ 
(NestList[Join, {#1, #2}, Floor[(Length@#1)/2]] & @@ {#, .25 + #} &
 @Range[0, #, .5] &)

Using Table again (less cluttered and more general):

 mat4:= Table[{#1, #2}[[1 + Mod[i, 2]]], {i, #3}] &;
 mat4[{a, b, c, d}, {e, f, g}, 5]
 (* gives *)
{{e, f, g}, {a, b, c, d}, {e, f, g}, {a, b, c, d}, {e, f, g}}
deleted 152 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 44 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 324 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
deleted 117 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
deleted 127 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 126 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
Post Undeleted by kglr
added 225 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
Post Deleted by kglr
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading