Mode 1: count 0 … 2n−1 as subsets. Mode 2: walk the submasks of a mask with s = (s − 1) & mask.
for mask in 0 .. 2ⁿ−1 treats each integer as a subset. Watch the bit row turn each integer into the set of present elements; the log records every one of the 2ⁿ subsets in increasing integer order.s = (s − 1) & mask walks every subset contained in it, in strictly decreasing order, ending at the empty set 0. Amber-bordered bits are in the mask; green-filled bits are in the current submask.Step advances one subset/submask; Run auto-plays; Reset rebuilds with the current n and mask.mask = 0 — the only submask is the empty set, so the walk is a single step. Set mask = (1<<n)−1 — every subset is a submask, so Mode 2 matches Mode 1 exactly.{0..n-1} is the integer whose bit i is 1 iff element i is present.
The submask loop visits exactly 2popcount(mask) submasks; summed over all masks this is 3n.
See junior.md, middle.md, and professional.md.