#include<stdio.h> typedef char int_8; typedef short int_16; const int_8 v[12] = {0, 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15}; void numtodigit(int_16 num, int_8 *digit, int_8 length) { int_8 i; for(i=0; i<length; i++) { digit[i] = num % 2; num = num >> 1; } } int main () { int_8 hamming[16], res, i, sum; int_16 num, set[17]; /* There are a total of 4096 subsets of {0, 1, ..., 15} such that the bitwise-xor of the set members gives zero. Each value of num in the range [0, 4096) will fill each hamming[i] with either 0 or 1. The set S can thusly be determined by the indices such that hamming[i] = 1, with hamming[i] = 1 implying 0, 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 1, 2, 4, 8 in S for i = 0..15 respectively. For example, when num = 2021, hamming[i] = 1 for i = 0, 2, 5, 6, 7, 8, 9, 10, 13, giving S = {0, 5, 9, 10, 11, 12, 13, 14, 2} with |S| = 8. */ for(i=0; i<=16; i++) { set[i] = 0; } for(num=0; num<4096; num++) { res = 0; sum = 0; numtodigit(num, hamming, 12); for(i=0; i<12; i++) { if(hamming[i] != 0) { res = res ^ v[i]; sum++; } } numtodigit(res, hamming+12, 4); for(; i<16; i++) { if(hamming[i] == 1) { sum++; } } set[sum]++; } for(i=0; i<=16; i++) { printf("%d, ", set[i]); } }