# Partitioning a set of integers

I have a set of ordered integers, e.g. {1,2,3,6,7,9,10} and I would like to partition the set in subsets of sequential numbers, e.g. {{1,2,3},{6,7},{9,10}}. Is there an easy way to do this?

Split[{1, 2, 3, 6, 7, 9, 10}, #2 - #1 == 1 &]


{{1, 2, 3}, {6, 7}, {9, 10}}

• How come you're using Chop here? It works fine without it. Oct 30 '18 at 22:55

Also

FindClusters[{1, 2, 3, 6, 7, 9, 10}]

• FindClusters is O(sqrt n), but split is O(n log n)
– M.R.
Oct 31 '18 at 17:14
• @M.R. Really, thx for the information! I didn't know it. Oct 31 '18 at 23:54