# Order in a subset

Lets consider a range of "K" binary digit numbers. In that range, we want to take a subset of those values which have (<="n" consecutive 0s) AND (<="n" consecutive 1s).

Then, we want to find the order of values in the resulting subset incrementally.

Also, we want to do the "un-ordering" of the values. i.e. find the value of the subset from the given order.

Note: The order must be found only by checking the subset value, and not by trying to iterate all values upto that value. This will be efficient for a large "K" range of digits.

Example:

K = 6

n <= 2 consecutive 0s AND 1s

000000 -> (>2 consecutive 0s OR 1s) -> remove from subset
000001 -> (>2 consecutive 0s OR 1s) -> remove from subset
000010 -> (>2 consecutive 0s OR 1s) -> remove from subset
000011 -> (>2 consecutive 0s OR 1s) -> remove from subset
000100 -> (>2 consecutive 0s OR 1s) -> remove from subset
000101 -> (>2 consecutive 0s OR 1s) -> remove from subset
000110 -> (>2 consecutive 0s OR 1s) -> remove from subset
000111 -> (>2 consecutive 0s OR 1s) -> remove from subset
001000 -> (>2 consecutive 0s OR 1s) -> remove from subset
001001 -> (<= 2 consecutive 0s AND 1s) -> order [1]
001010 -> (<= 2 consecutive 0s AND 1s) -> order [2]
001011 -> (<= 2 consecutive 0s AND 1s) -> order [3]
001100 -> (<= 2 consecutive 0s AND 1s) -> order [4]
001101 -> (<= 2 consecutive 0s AND 1s) -> order [5]
001110 -> (>2 consecutive 0s OR 1s) -> remove from subset
001111 -> (>2 consecutive 0s OR 1s) -> remove from subset

010000 -> (>2 consecutive 0s OR 1s) -> remove from subset
010001 -> (>2 consecutive 0s OR 1s) -> remove from subset
010010 -> (<= 2 consecutive 0s AND 1s) -> order [6]
010011 -> (<= 2 consecutive 0s AND 1s) -> order [7]
010100 -> (<= 2 consecutive 0s AND 1s) -> order [8]
010101 -> (<= 2 consecutive 0s AND 1s) -> order [9]
010110 -> (<= 2 consecutive 0s AND 1s) -> order [10]
010111 -> (>2 consecutive 0s OR 1s) -> remove from subset
011000 -> (>2 consecutive 0s OR 1s) -> remove from subset
011001 -> (<= 2 consecutive 0s AND 1s) -> order [11]
011010 -> (<= 2 consecutive 0s AND 1s) -> order [12]
011011 -> (<= 2 consecutive 0s AND 1s) -> order [13]
011100 -> (>2 consecutive 0s OR 1s) -> remove from subset
011101 -> (>2 consecutive 0s OR 1s) -> remove from subset
011110 -> (>2 consecutive 0s OR 1s) -> remove from subset
011111 -> (>2 consecutive 0s OR 1s) -> remove from subset

100000 -> (>2 consecutive 0s OR 1s) -> remove from subset
100001 -> (>2 consecutive 0s OR 1s) -> remove from subset
100010 -> (>2 consecutive 0s OR 1s) -> remove from subset
100011 -> (>2 consecutive 0s OR 1s) -> remove from subset
100100 -> (<= 2 consecutive 0s AND 1s) -> order [14]
100101 -> (<= 2 consecutive 0s AND 1s) -> order [15]
100110 -> (<= 2 consecutive 0s AND 1s) -> order [16]
100111 -> (>2 consecutive 0s OR 1s) -> remove from subset
101000 -> (>2 consecutive 0s OR 1s) -> remove from subset
101001 -> (<= 2 consecutive 0s AND 1s) -> order [17]
101010 -> (<= 2 consecutive 0s AND 1s) -> order [18]
101011 -> (<= 2 consecutive 0s AND 1s) -> order [19]
101100 -> (<= 2 consecutive 0s AND 1s) -> order [20]
101101 -> (<= 2 consecutive 0s AND 1s) -> order [21]
101110 -> (>2 consecutive 0s OR 1s) -> remove from subset
101111 -> (>2 consecutive 0s OR 1s) -> remove from subset

110000 -> (>2 consecutive 0s OR 1s) -> remove from subset
110001 -> (>2 consecutive 0s OR 1s) -> remove from subset
110010 -> (<= 2 consecutive 0s AND 1s) -> order [22]
110011 -> (<= 2 consecutive 0s AND 1s) -> order [23]
110100 -> (<= 2 consecutive 0s AND 1s) -> order [24]
110101 -> (<= 2 consecutive 0s AND 1s) -> order [25]
110110 -> (<= 2 consecutive 0s AND 1s) -> order [26]
110111 -> (>2 consecutive 0s OR 1s) -> remove from subset
111000 -> (>2 consecutive 0s OR 1s) -> remove from subset
111001 -> (>2 consecutive 0s OR 1s) -> remove from subset
111010 -> (>2 consecutive 0s OR 1s) -> remove from subset
111011 -> (>2 consecutive 0s OR 1s) -> remove from subset
111100 -> (>2 consecutive 0s OR 1s) -> remove from subset
111101 -> (>2 consecutive 0s OR 1s) -> remove from subset
111110 -> (>2 consecutive 0s OR 1s) -> remove from subset
111111 -> (>2 consecutive 0s OR 1s) -> remove from subset

• Welcome to Scicomp! Could you clearify what your question is? You seem to already have some code. Commented Sep 21, 2023 at 8:04
• If you consider the binary numbers as the corners of a hypercube, can you describe which numbers are "allowed" in the form of relatively simply linear constraints? If so, the "allowed" region is a polyhedron, and the points you allow are the integer lattice points in this polyhedron. You might then be able to find a function that provides the ordering. Commented Sep 21, 2023 at 19:49