File size: 1,014 Bytes
b27bfb3 | 1 2 3 4 5 | {"type": "session", "harness": "opencode", "id": "math-0152", "name": "Bit Manipulation Math"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain bit manipulation mathematics"}}
{"type": "message", "message": {"role": "assistant", "content": "Popcount: number of set bits. Kernighan: x & (x-1) clears lowest set bit. Loop until x=0.\nXOR properties: a^a=0, a^0=a, commutative/associative. Missing number: XOR all nums and indices.\nBitmasks for subsets: iterate subsets of {0..n-1}: for(mask=0; mask<(1<<n); mask++) for(i=0; i<n; i++) if(mask&(1<<i)).\nSubsets of subsets: for(sub=mask; sub; sub=(sub-1)&mask) iterates all non-empty submasks.\nSingle-bit operations: isolate lowest bit (x&(-x)), position (__builtin_ctz), count (__builtin_popcount).\nBit DP: dp[mask] = best value for subset represented by mask. TSP: dp[mask][i] = min cost visiting nodes in mask ending at i."}}
|