There are similar questions here I haven't seen one where the there is an overlap.
The requirements:
- The result should be N sub lists with the overlap specified.
- There should be no dropped elements
- The sub-lists should have lengths that are as even as possible, i.e. there should be a minimum number of different sub-list lengths and the difference between sub-list lengths should be minimized.
For example, given Range[10]
and overlap of 1 this would be the output for different numbers of sub-lists:
N Output
1 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}
2 {{1, 2, 3, 4, 5, 6}, {6, 7, 8, 9, 10}}
3 {{1, 2, 3, 4}, {4, 5, 6, 7}, {7, 8, 9, 10}}
4 {{1, 2, 3, 4}, {4, 5, 6}, {6, 7, 8}, {8, 9, 10}}
5 {{1, 2, 3}, {3, 4, 5}, {5, 6, 7}, {7, 8, 9}, {9, 10}}
6 {{1, 2, 3}, {3, 4, 5}, {5, 6, 7}, {7, 8}, {8, 9}, {9, 10}}
7 {{1, 2, 3}, {3, 4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10}}
8 {{1, 2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10}}
9 {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10}}
Note: Above is an example done by hand and it is not a requirement that the splitting be done as in the example above. So for example for N = 4 either of the following would be valid:
{{1, 2, 3, 4}, {4, 5, 6}, {6, 7, 8}, {8, 9, 10}}
{{1, 2, 3}, {3, 4, 5}, {5, 6, 7}, {7, 8, 9, 10}}