Lets define the process of crushing an array of numbers. In a crush we read the array left to right. If at a point we encounter two of the same element in a row we remove the first one and double the second one. For example here is the process of crushing the following array
[5,2,2,3]
^
[5,2,2,3]
^
[5,2,2,3]
^
[5,4,3]
^
[5,4,3]
^
The same element can be collapsed multiple times, for example [1,1,2]
becomes [4]
when crushed.
We will call an array uncrushable when the process of crushing that array does not change it. For example [1,2,3]
is still [1,2,3]
after being crushed.
Your task is to take an array and determine the number of crushes required to make it uncrushable. You need only support integers on the range of 0 to 232-1
This is code-golf so answers will be scored in bytes with less bytes being better.
Test Cases
[1] -> 0
[1,1] -> 1
[2,1,1] -> 2
[4,2,1,1] -> 3
[2,2,2,1,1] -> 3
[0,0,0,0] -> 1
[4,0,0,0,4] -> 1
[4,0,0,0,0,4] -> 1
[] -> 0
[1,1,2,4,8]
return 1 or 4? \$\endgroup\$