You have two boxes, one is filled with 10 items and the other is empty. You are allowed to transfer items one at a time from one box to the other (transfers may to either way).
There are 2^10=1024 ways to split the items between the two boxes. Can you make all the ways without repetition using only the transfer rule described above?
(In reply to
solution by Charlie)
OPEN "10items2.txt" FOR OUTPUT AS #2
FOR i = 0 TO 1023
s$ = ""
n = i
FOR j = 1 TO 10
s$ = LTRIM$(STR$(n MOD 2)) + s$
n = n \ 2
NEXT j
PRINT s$; " "; ' binary notation
FOR p = 10 TO 2 STEP 1
IF MID$(s$, p  1, 1) = "1" THEN
MID$(s$, p, 1) = LTRIM$(STR$(1  VAL(MID$(s$, p, 1))))
END IF
NEXT ' now it's gray code
PRINT s$
FOR j = 1 TO 10
IF MID$(s$, j, 1) = "1" THEN PRINT #2, MID$("abcdefghij", j, 1);
NEXT j
PRINT #2, " ";
FOR j = 1 TO 10
IF MID$(s$, j, 1) = "0" THEN PRINT #2, MID$("abcdefghij", j, 1);
NEXT j
PRINT #2,
NEXT
CLOSE

Posted by Charlie
on 20130813 01:54:34 