Basically you're looking at a fancy table lookup. Build a table of Gray codes for however many bits you're comparing and then look for two adjacent numbers in the list that match the codes in your table. Repeat until your computer chokes and dies.
One easy way to build a Gray code table is to start with a hard coded table for two bits:
00, 01, 11, 10
Copy and reverse the table:
10, 11, 01, 00
Prefix the codes in the first table with 0:
000, 001, 011, 010
Prefix the codes in the second table with 1:
110, 111, 101, 100
Append the second table to the first:
000, 001, 011, 010, 110, 111, 101, 100
This can be used for a table up to as many bits as you want, but keep in mind that there are multiple permutations for Gray codes. Your program specification is vague enough that keeping to it will be very difficult. This in particular is disturbing:
1)all singletons
2)all duets
3)all quads
and so on.
;)