4
$\begingroup$

Assume I have the list below.

 list=Range@20; 

Desired partition is:

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

I have tried

Partition[Range@20, 4, 3] 

and

FoldPairList[TakeDrop, Range@20, Range[4, 6]] 

does not give me what I want. Any suggestion?

$\endgroup$
2
  • $\begingroup$ What determines the size of the sublist? $\endgroup$ Commented Jan 22, 2018 at 7:07
  • $\begingroup$ I would like to overlap the end point $\endgroup$ Commented Jan 22, 2018 at 7:11

2 Answers 2

6
$\begingroup$
Partition[Range @ 20, 5, 4, {2, 2}, {}] 

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

$\endgroup$
3
$\begingroup$

I found this solution:

Join[{Range@4}, Partition[Range[4, 20], 5, 4]] 

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

If there is other solution I would like to see them as well.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.