4

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?

OkkesDulgerci
  • 10,716
  • 1
  • 19
  • 38

2 Answers2

6
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}}

kglr
  • 394,356
  • 18
  • 477
  • 896
3

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.

OkkesDulgerci
  • 10,716
  • 1
  • 19
  • 38