Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
Santa likes to sort his presents in a special way. He keeps "uninterleaving" the pile of presents into smaller sub-piles until each sub-pile is either full of toys or full of coal.
Your job is to, given a pile of presents, determine the maximum number of uninterleavings.
Uninterleaving a pile of presents, (eg. \$1011011\$), means separating every second
item and every second + 1
item into its own sub-pile (\$1101\$, \$011\$).
Sorting \$010011100101\$ would be (implies that \$1\$ is a present full of toys and \$0\$ is a present full of coal):
- 010011100101
- 001100
- 010
- 00
- 1
- 010
- 00
- 1
- 101011
- 111
- 001
- 01
- 0
- 1
- 0
The answer would be the maximum number of times Santa has to uninterleave the presents (from \$010011100101\$ to \$0\$ or \$1\$), \$4\$.
The shortest code wins. code-golf
Test cases
[In]: 1
[Out]: 0
[In]: 1010101
[Out]: 1
[In]: 101011
[Out]: 3
[In]: 1011001101110001101011100
[Out]: 5
```
1011001101110001101011100 -> 1101010011110 -> 1000110 -> 001 -> 01
. \$\endgroup\$1
is 1, then shouldn't101011
be 3, not 2? It has 3 levels of indendation. Similarly, it seems like1010101
must be 1, as it must be at least 1 greater than1
, which is already uninterleaved. \$\endgroup\$1
to0
? Or should I increment the other examples? (I did the former for now) \$\endgroup\$