r/counting • u/TehVulpez • 20h ago
Constant-weight binary | 1 0010 1000 0110
Thanks to h0rseycat for the run and assist!
In this thread, we count binary strings in segments of length (how many bits they have) and weight (how many ones they have). All the counts in a segment have the same number of bits and number of ones. This only changes when we reach the highest number of that length and weight, when we increase the weight and start over from the lowest possible number. Or, if the previous count was all ones, we add a new bit and start over with all zeroes.
To find the next binary number with m ones out of n bits:
Find the rightmost 1 which has a 0 to its left and slide it one bit to the left.
If that bit had one or more 1s immediately to its right, then arrange those remaining 1s all the way on the right side.
Next get is at 0 1011 0111 0000