I have a perfect binary tree with an arbitrary depth. I have been trying to come up with an equation to describe how many times in a row a leaf node has moved the same direction. For example, the leftmost and rightmost leaf nodes will have moved the same direction every time and the innermost leaf nodes will have moved the same direction every time after the first move. You could also think of it as traveling from root to leaf, and any time you change direction, the number of times moving in the same direction resets back to 1.
I've been trying to discover a way to plug in a leaf node index and get this number. Is this possible?
To summarize using the picture above, I want to be able to give the function an index, e.g. 7, and get the number of times in a row it has moved the same direction, e.g. 3.