“Coolex: The Coolest Way to Generate Combinations”, Frank Ruskey, Aaron Williams2009-09-06 (, )⁠:

We present a practical and elegant method for generating all (s, t)-combinations (binary strings with s zeros and t ones): Identify the shortest prefix ending in 010 or 011 (or the entire string if no such prefix exists), and rotate it by one position to the right.

This iterative rule gives an order to (s, t)-combinations that is circular and genlex. Moreover, the rotated portion of the string always contains at most 4 contiguous runs of zeros and ones, so every iteration can be achieved by transposing at most 2 pairs of bits. This leads to an efficient loopless and branchless implementation that consists only of 2 variables and 6 assignment statements. The order also has a number of striking similarities to colex order, especially its recursive definition and ranking algorithm.

In the light of these similarities we have named our order cool-lex!

[Keywords: Gray code order, combinations, binary strings, Colex, loopless algorithm, branchless algorithm, constant extra space, prefix rotation, prefix shift]