I was looking through the questions: Fast way to get a position of combination (without repetitions) and (Fast way to) Get a combination given its position in (reverse-)lexicographic order for converting a combination to its lexicographic position and then going from the position to the combination. A logical extension of this is the generalized Catalan numbers which are basically combinations with an additional constraint.
Consider a gambler tossing a coin and winning 1\$ on heads and losing 1\$ on tails. We know he got $l$ tails and $l+k$ heads. The number of ways he could have done this is: ${k+2l \choose l}$ and if we wanted to generate the actual paths, we can do so using the approaches in the questions linked above (the binary representations of the combinations would be the tosses at which he got tails).
But now, we add the further constraint that he reaches $k\$$ for the first time after $k+2l$ tosses. The post: Probability that random walk will reach state $k$ for the first time on step $n$ shows that the number of ways to do this becomes: ${k+2l-1 \choose l} - {k+2l-1 \choose l-1}$. Now, I want to loop through these paths. So, just as the first two posts above show how to go from combinations to lexicographic position and back, is there an efficient way to do this for these paths as well (that doesn't involve storing all paths in memory). For this question, let's consider we're given a path in binary. Something like: [0,1,0,0,0,1,1] (1's are tosses where he got tails) and want to get an integer which is the lexicographic position if you list all the valid paths (the total number of which is the generalized Catalan number).