Grouping takes a list and splits it into new lists of equal adjacent elements. For example
[1,1,2,1,1] -> [[1,1],[2],[1,1]]
If you then take the length of these groups you get a new list of integers
[1,1,2,1,1] -> [2,1,2]
Your task is to write a program that takes a list of positive integers and find the number of times you can group and length it before the resulting list has a single element. For example the list [1,2,3,3,2,1]
can be regrouped 4 times
[1,2,3,3,2,1]
[1,1,2,1,1]
[2,1,2]
[1,1,1]
[3]
This is code-golf so answers will be scored in bytes with fewer bytes being better.
Test cases
[1,2,3,3,2,1] -> 4
[1,2,3,4,5,6,7] -> 2
[1,1,1,1,1,1] -> 1
[2] -> 0
[1,2,4] -> 2
[1,2,2,1,1,2] -> 4
[1,2,2,1,1,2,1,2,2] -> 5
[1] -> 0
[1]
is a valid input and should give0
, correct? \$\endgroup\$