I've encountered a particular problem and was wondering if anyone has any insights on how to approach it more efficiently or elegantly.
To be accurate, given the list:
list = {2, 5, 8, 12, 16, 20, 24, 28, 31};
I'm looking to generate pairs of consecutive elements in the following manner:
{{1, 2}, {3, 5}, {6, 8}, {9, 12}, {13, 16}, {17, 20}, {21, 24}, {25, 28}, {29, 31}}
Currently, I'm using the following code:
Table[{If[i == 1, 0, list[[i - 1]]] + 1, list[[i]]}, {i, 1, Length@list}]
The above code works, but I'm interested in knowing if there is a more elegant or efficient way to achieve the same result.
I would appreciate any suggestions or alternative approaches anyone in the community may have. Thanks in advance!