Brute forcing is nice and simple but I feel a bit of a hack. I like the idea of making a tree of dyadic rationals, and seeing each node as double-filled. Most of the work is done if you just move one copy to the left child and one copy to the right child. That way everything except 1/2 gets a single copy, and 1/2 has none. From there, you can just shift up the entirely left path back to where it was. To lay out how the mapping would actually work: if the sequence is 000...001111... or 00000... or 1111... or doesn't meet the conditions below (representing a dyadic rational), then just use the associated real number from the infinite sum of powers of 1/2 If the sequence is b1,b2,b3,...,bn,00000... (where bn = 1) then use the associated real number + 1/2^(n+1) If the sequence is b1,b2,b3,...,bn,11111... (where bn = 0) then use the associated real number - 1/2^(n+1)