I came across the difficulty of understanding the logic of interaction of the fourth and fifth arguments of Partition
.
Here is an example:
l = Range[7];
p1 = Partition[l, 2, 1, {-1, 1}, {a}]
p2 = Partition[l, 2, 1, {-1, 1}, {a, b}]
p3 = Partition[l, 2, 1, {-1, 1}, {a, b, c}]
p4 = Partition[l, 2, 1, {-1, 1}, {a, b, c, d}]
{{a, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, a}} {{b, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, b}} {{c, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, b}} {{d, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, d}}
What is the logic behind padding the list from the right? Why both in p2
and p3
the last element is b
? Why at the same time in p4
the last element is d
?
Similarly, please explain the following:
p5 = Partition[l, 3, 1, {-1, 1}, {a, b}]
p6 = Partition[l, 3, 1, {-1, 1}, {a, b, c}]
p7 = Partition[l, 3, 1, {-1, 1}, {a, b, c, d}]
p8 = Partition[l, 3, 1, {-1, 1}, {a, b, c, d, e}]
{{a, b, 1}, {b, 1, 2}, {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}, {5, 6, 7}, {6, 7, b}, {7, b, a}} {{b, c, 1}, {c, 1, 2}, {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}, {5, 6, 7}, {6, 7, b}, {7, b, c}} {{c, d, 1}, {d, 1, 2}, {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}, {5, 6, 7}, {6, 7, d}, {7, d, a}} {{d, e, 1}, {e, 1, 2}, {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}, {5, 6, 7}, {6, 7, c}, {7, c, d}}
And also this:
p9 = Partition[l, 3, 1, {2, 2}, {a, b}]
p10 = Partition[l, 3, 1, {2, 2}, {a, b, c}]
p11 = Partition[l, 3, 1, {2, 2}, {a, b, c, d}]
p12 = Partition[l, 3, 1, {2, 2}, {a, b, c, d, e}]
{{b, 1, 2}, {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}, {5, 6, 7}, {6, 7, b}} {{c, 1, 2}, {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}, {5, 6, 7}, {6, 7, b}} {{d, 1, 2}, {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}, {5, 6, 7}, {6, 7, d}} {{e, 1, 2}, {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}, {5, 6, 7}, {6, 7, c}}
Is it possible to make Partition[l, 3, 1, {2, 2}, ?????]
returning {{a, 1, 2}, {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}, {5, 6, 7}, {6, 7, b}}
?
Partition[l, 3, 1, {2, 2}, {"", b, a}]
$\endgroup$l = Range[8];
. $\endgroup$Partition[Range@n,3,1,2,Join[Table[1,Floor[(n-1)/2]-1],{b,b,a}]]
. This is about the same as @MichaelE2 answer. $\endgroup$