Skip to main content
added 292 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
lst1 = TakeList[Range @ 21, Range @ 6]

{{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20, 21}}

lst2 = Table[lst1[[i ;;, i]], {i, 6}]

{{1, 2, 4, 7, 11, 16}, {3, 5, 8, 12, 17}, {6, 9, 13, 18}, {10, 14, 19}, {15, 20}, {21}}

lst3 = Table[lst1[[i ;;, -i]], {i, 6}]

{{1, 3, 6, 10, 15, 21}, {2, 5, 9, 14, 20}, {4, 8, 13, 19}, {7, 12, 18}, {11, 17}, {16}}

ClearAll[threeLists]
threeLists[n_] := Module[{l = TakeList[Range[n (n + 1)/2], Range @ n]}, {l, ## & @@ 
    Table[l[[i ;;, (-1)^j  i]], {j, 0, 1}, {i, n} ]}]

threeLists[6] == {lst1, lst2, lst3}

True

threeLists[3] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\}\} \\ \{\{1,2,4\},\{3,5\},\{6\}\} \\ \{\{1,3,6\},\{2,5\},\{4\}\} \\ \end{array}$

threeLists[4] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\}\} \\ \{\{1,2,4,7\},\{3,5,8\},\{6,9\},\{10\}\} \\ \{\{1,3,6,10\},\{2,5,9\},\{4,8\},\{7\}\} \\ \end{array}$

threeLists[6] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\},\{11,12,13,14,15\},\{16,17,18,19,20,21\}\} \\ \{\{1,2,4,7,11,16\},\{3,5,8,12,17\},\{6,9,13,18\},\{10,14,19\},\{15,20\},\{21\}\} \\ \{\{1,3,6,10,15,21\},\{2,5,9,14,20\},\{4,8,13,19\},\{7,12,18\},\{11,17\},\{16\}\} \\ \end{array}$

An alternative formulation using NestList:

ClearAll[f, threeLists2]

f = Map[DeleteCases @ 0] @* Transpose @* PadRight;

threeLists2 = NestList[f, TakeList[Range[# (# + 1)/2], Range @ #], 2] &;

threeLists2 /@ Range[100] == threeLists /@ Range[100]

True

lst1 = TakeList[Range @ 21, Range @ 6]

{{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20, 21}}

lst2 = Table[lst1[[i ;;, i]], {i, 6}]

{{1, 2, 4, 7, 11, 16}, {3, 5, 8, 12, 17}, {6, 9, 13, 18}, {10, 14, 19}, {15, 20}, {21}}

lst3 = Table[lst1[[i ;;, -i]], {i, 6}]

{{1, 3, 6, 10, 15, 21}, {2, 5, 9, 14, 20}, {4, 8, 13, 19}, {7, 12, 18}, {11, 17}, {16}}

ClearAll[threeLists]
threeLists[n_] := Module[{l = TakeList[Range[n (n + 1)/2], Range @ n]}, {l, ## & @@ 
    Table[l[[i ;;, (-1)^j  i]], {j, 0, 1}, {i, n} ]}]

threeLists[6] == {lst1, lst2, lst3}

True

threeLists[3] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\}\} \\ \{\{1,2,4\},\{3,5\},\{6\}\} \\ \{\{1,3,6\},\{2,5\},\{4\}\} \\ \end{array}$

threeLists[4] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\}\} \\ \{\{1,2,4,7\},\{3,5,8\},\{6,9\},\{10\}\} \\ \{\{1,3,6,10\},\{2,5,9\},\{4,8\},\{7\}\} \\ \end{array}$

threeLists[6] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\},\{11,12,13,14,15\},\{16,17,18,19,20,21\}\} \\ \{\{1,2,4,7,11,16\},\{3,5,8,12,17\},\{6,9,13,18\},\{10,14,19\},\{15,20\},\{21\}\} \\ \{\{1,3,6,10,15,21\},\{2,5,9,14,20\},\{4,8,13,19\},\{7,12,18\},\{11,17\},\{16\}\} \\ \end{array}$

lst1 = TakeList[Range @ 21, Range @ 6]

{{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20, 21}}

lst2 = Table[lst1[[i ;;, i]], {i, 6}]

{{1, 2, 4, 7, 11, 16}, {3, 5, 8, 12, 17}, {6, 9, 13, 18}, {10, 14, 19}, {15, 20}, {21}}

lst3 = Table[lst1[[i ;;, -i]], {i, 6}]

{{1, 3, 6, 10, 15, 21}, {2, 5, 9, 14, 20}, {4, 8, 13, 19}, {7, 12, 18}, {11, 17}, {16}}

ClearAll[threeLists]
threeLists[n_] := Module[{l = TakeList[Range[n (n + 1)/2], Range @ n]}, {l, ## & @@ 
    Table[l[[i ;;, (-1)^j  i]], {j, 0, 1}, {i, n} ]}]

threeLists[6] == {lst1, lst2, lst3}

True

threeLists[3] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\}\} \\ \{\{1,2,4\},\{3,5\},\{6\}\} \\ \{\{1,3,6\},\{2,5\},\{4\}\} \\ \end{array}$

threeLists[4] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\}\} \\ \{\{1,2,4,7\},\{3,5,8\},\{6,9\},\{10\}\} \\ \{\{1,3,6,10\},\{2,5,9\},\{4,8\},\{7\}\} \\ \end{array}$

threeLists[6] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\},\{11,12,13,14,15\},\{16,17,18,19,20,21\}\} \\ \{\{1,2,4,7,11,16\},\{3,5,8,12,17\},\{6,9,13,18\},\{10,14,19\},\{15,20\},\{21\}\} \\ \{\{1,3,6,10,15,21\},\{2,5,9,14,20\},\{4,8,13,19\},\{7,12,18\},\{11,17\},\{16\}\} \\ \end{array}$

An alternative formulation using NestList:

ClearAll[f, threeLists2]

f = Map[DeleteCases @ 0] @* Transpose @* PadRight;

threeLists2 = NestList[f, TakeList[Range[# (# + 1)/2], Range @ #], 2] &;

threeLists2 /@ Range[100] == threeLists /@ Range[100]

True

edited body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
lst1 = TakeList[Range @ 21, Range @ 6]

{{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20, 21}}

lst2 = Table[lst1[[i ;;, i]], {i, 6}]

{{1, 2, 4, 7, 11, 16}, {3, 5, 8, 12, 17}, {6, 9, 13, 18}, {10, 14, 19}, {15, 20}, {21}}

lst3 = Table[lst1[[i ;;, -i]], {i, 6}]

{{1, 3, 6, 10, 15, 21}, {2, 5, 9, 14, 20}, {4, 8, 13, 19}, {7, 12, 18}, {11, 17}, {16}}

ClearAll[threeLists]
threeLists[n_] := Module[{l = TakeList[Range[n (n + 1)/2], Range @ #]n]}, {l, ## & @@ 
    Table[l[[i ;;, (-1)^j  i]], {j, 0, 1}, {i, n} ]}]

threeLists[6] == {lst1, lst2, lst3}

True

threeLists[3] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\}\} \\ \{\{1,2,4\},\{3,5\},\{6\}\} \\ \{\{1,3,6\},\{2,5\},\{4\}\} \\ \end{array}$

threeLists[4] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\}\} \\ \{\{1,2,4,7\},\{3,5,8\},\{6,9\},\{10\}\} \\ \{\{1,3,6,10\},\{2,5,9\},\{4,8\},\{7\}\} \\ \end{array}$

threeLists[6] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\},\{11,12,13,14,15\},\{16,17,18,19,20,21\}\} \\ \{\{1,2,4,7,11,16\},\{3,5,8,12,17\},\{6,9,13,18\},\{10,14,19\},\{15,20\},\{21\}\} \\ \{\{1,3,6,10,15,21\},\{2,5,9,14,20\},\{4,8,13,19\},\{7,12,18\},\{11,17\},\{16\}\} \\ \end{array}$

lst1 = TakeList[Range @ 21, Range @ 6]

{{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20, 21}}

lst2 = Table[lst1[[i ;;, i]], {i, 6}]

{{1, 2, 4, 7, 11, 16}, {3, 5, 8, 12, 17}, {6, 9, 13, 18}, {10, 14, 19}, {15, 20}, {21}}

lst3 = Table[lst1[[i ;;, -i]], {i, 6}]

{{1, 3, 6, 10, 15, 21}, {2, 5, 9, 14, 20}, {4, 8, 13, 19}, {7, 12, 18}, {11, 17}, {16}}

ClearAll[threeLists]
threeLists[n_] := Module[{l = TakeList[Range[n (n + 1)/2], Range @ #]}, {l, ## & @@ 
    Table[l[[i ;;, (-1)^j  i]], {j, 0, 1}, {i, n} ]}]

threeLists[6] == {lst1, lst2, lst3}

True

threeLists[3] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\}\} \\ \{\{1,2,4\},\{3,5\},\{6\}\} \\ \{\{1,3,6\},\{2,5\},\{4\}\} \\ \end{array}$

threeLists[4] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\}\} \\ \{\{1,2,4,7\},\{3,5,8\},\{6,9\},\{10\}\} \\ \{\{1,3,6,10\},\{2,5,9\},\{4,8\},\{7\}\} \\ \end{array}$

threeLists[6] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\},\{11,12,13,14,15\},\{16,17,18,19,20,21\}\} \\ \{\{1,2,4,7,11,16\},\{3,5,8,12,17\},\{6,9,13,18\},\{10,14,19\},\{15,20\},\{21\}\} \\ \{\{1,3,6,10,15,21\},\{2,5,9,14,20\},\{4,8,13,19\},\{7,12,18\},\{11,17\},\{16\}\} \\ \end{array}$

lst1 = TakeList[Range @ 21, Range @ 6]

{{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20, 21}}

lst2 = Table[lst1[[i ;;, i]], {i, 6}]

{{1, 2, 4, 7, 11, 16}, {3, 5, 8, 12, 17}, {6, 9, 13, 18}, {10, 14, 19}, {15, 20}, {21}}

lst3 = Table[lst1[[i ;;, -i]], {i, 6}]

{{1, 3, 6, 10, 15, 21}, {2, 5, 9, 14, 20}, {4, 8, 13, 19}, {7, 12, 18}, {11, 17}, {16}}

ClearAll[threeLists]
threeLists[n_] := Module[{l = TakeList[Range[n (n + 1)/2], Range @ n]}, {l, ## & @@ 
    Table[l[[i ;;, (-1)^j  i]], {j, 0, 1}, {i, n} ]}]

threeLists[6] == {lst1, lst2, lst3}

True

threeLists[3] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\}\} \\ \{\{1,2,4\},\{3,5\},\{6\}\} \\ \{\{1,3,6\},\{2,5\},\{4\}\} \\ \end{array}$

threeLists[4] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\}\} \\ \{\{1,2,4,7\},\{3,5,8\},\{6,9\},\{10\}\} \\ \{\{1,3,6,10\},\{2,5,9\},\{4,8\},\{7\}\} \\ \end{array}$

threeLists[6] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\},\{11,12,13,14,15\},\{16,17,18,19,20,21\}\} \\ \{\{1,2,4,7,11,16\},\{3,5,8,12,17\},\{6,9,13,18\},\{10,14,19\},\{15,20\},\{21\}\} \\ \{\{1,3,6,10,15,21\},\{2,5,9,14,20\},\{4,8,13,19\},\{7,12,18\},\{11,17\},\{16\}\} \\ \end{array}$

added 959 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
lst1 = TakeList[Range @ 21, Range @ 6]

{{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20, 21}}

lst2 = Table[lst1[[i ;;, i]], {i, 6}]

{{1, 2, 4, 7, 11, 16}, {3, 5, 8, 12, 17}, {6, 9, 13, 18}, {10, 14, 19}, {15, 20}, {21}}

lst3 = Table[lst1[[i ;;, -i]], {i, 6}]

{{1, 3, 6, 10, 15, 21}, {2, 5, 9, 14, 20}, {4, 8, 13, 19}, {7, 12, 18}, {11, 17}, {16}}

ClearAll[threeLists]
threeLists[n_] := Module[{l = TakeList[Range[n (n + 1)/2], Range @ #]}, {l, ## & @@ 
    Table[l[[i ;;, (-1)^j  i]], {j, 0, 1}, {i, n} ]}]

threeLists[6] == {lst1, lst2, lst3}

True

threeLists[3] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\}\} \\ \{\{1,2,4\},\{3,5\},\{6\}\} \\ \{\{1,3,6\},\{2,5\},\{4\}\} \\ \end{array}$

threeLists[4] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\}\} \\ \{\{1,2,4,7\},\{3,5,8\},\{6,9\},\{10\}\} \\ \{\{1,3,6,10\},\{2,5,9\},\{4,8\},\{7\}\} \\ \end{array}$

threeLists[6] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\},\{11,12,13,14,15\},\{16,17,18,19,20,21\}\} \\ \{\{1,2,4,7,11,16\},\{3,5,8,12,17\},\{6,9,13,18\},\{10,14,19\},\{15,20\},\{21\}\} \\ \{\{1,3,6,10,15,21\},\{2,5,9,14,20\},\{4,8,13,19\},\{7,12,18\},\{11,17\},\{16\}\} \\ \end{array}$

lst1 = TakeList[Range @ 21, Range @ 6]

{{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20, 21}}

lst2 = Table[lst1[[i ;;, i]], {i, 6}]

{{1, 2, 4, 7, 11, 16}, {3, 5, 8, 12, 17}, {6, 9, 13, 18}, {10, 14, 19}, {15, 20}, {21}}

lst3 = Table[lst1[[i ;;, -i]], {i, 6}]

{{1, 3, 6, 10, 15, 21}, {2, 5, 9, 14, 20}, {4, 8, 13, 19}, {7, 12, 18}, {11, 17}, {16}}

lst1 = TakeList[Range @ 21, Range @ 6]

{{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20, 21}}

lst2 = Table[lst1[[i ;;, i]], {i, 6}]

{{1, 2, 4, 7, 11, 16}, {3, 5, 8, 12, 17}, {6, 9, 13, 18}, {10, 14, 19}, {15, 20}, {21}}

lst3 = Table[lst1[[i ;;, -i]], {i, 6}]

{{1, 3, 6, 10, 15, 21}, {2, 5, 9, 14, 20}, {4, 8, 13, 19}, {7, 12, 18}, {11, 17}, {16}}

ClearAll[threeLists]
threeLists[n_] := Module[{l = TakeList[Range[n (n + 1)/2], Range @ #]}, {l, ## & @@ 
    Table[l[[i ;;, (-1)^j  i]], {j, 0, 1}, {i, n} ]}]

threeLists[6] == {lst1, lst2, lst3}

True

threeLists[3] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\}\} \\ \{\{1,2,4\},\{3,5\},\{6\}\} \\ \{\{1,3,6\},\{2,5\},\{4\}\} \\ \end{array}$

threeLists[4] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\}\} \\ \{\{1,2,4,7\},\{3,5,8\},\{6,9\},\{10\}\} \\ \{\{1,3,6,10\},\{2,5,9\},\{4,8\},\{7\}\} \\ \end{array}$

threeLists[6] // Column // TeXForm

$\begin{array}{l} \{\{1\},\{2,3\},\{4,5,6\},\{7,8,9,10\},\{11,12,13,14,15\},\{16,17,18,19,20,21\}\} \\ \{\{1,2,4,7,11,16\},\{3,5,8,12,17\},\{6,9,13,18\},\{10,14,19\},\{15,20\},\{21\}\} \\ \{\{1,3,6,10,15,21\},\{2,5,9,14,20\},\{4,8,13,19\},\{7,12,18\},\{11,17\},\{16\}\} \\ \end{array}$

deleted 18 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading