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$
  • $\begingroup$ What determines the size of the sublist? $\endgroup$ – Kuba Jan 22 '18 at 7:07
  • $\begingroup$ I would like to overlap the end point $\endgroup$ – OkkesDulgerci Jan 22 '18 at 7:11
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$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.