I have an ordered string that I need to present to a user:
ABCCDDCBBBCBBDDBCAAA
Objects represented by ‘B’ are tagged, such that 2 Bs will have a ‘~’ after them.
AB~CCDDCB~BBCBBDDBCAAA
AB~CCDDCBB~BCBBDDBCAAA
AB~CCDDCBBB~CBBDDBCAAA
and so on...
I’ve used the combinations library by Howard Hinnant and it works well for this simple case. My test code uses a vector of locations as ints that was sent through for_each_combination.
However, I’m lost as to what to do when I have multiple tags for B.
For example, 4Bs total need to be tagged, 2 by ‘~’ and 2 by ‘#’
AB~CCDDCB~B#B#CBBDDBCAAA
AB#CCDDCB~B~B#CBBDDBCAAA
AB~CCDDCB#B~B#CBBDDBCAAA
AB#CCDDCB#B~B~CBBDDBCAAA
ABCCDDCB~B~B#CB#BDDBCAAA
and so on...
The pseudocode I’ve written out is a cascade. After the first for_each_combination, for each of the resulting combinations, copy every other location to another vector and do another for_each_combination.
Considering the number of combinations I will be working with, I’m hoping there’s a better way.
I believe I’ve answered my own question after a bit of looking.
First, I switched from using Howard’s library to Hervé’s combinations library. The main draw is that using next_combination allows me to chain the combination calculations together, like so:
I need to massage this into an iterator, but this is exactly what I need.