#include #include #include // Wikipedia: http://en.wikipedia.org/wiki/Binary_Golay_code // Roberts: http://mathcs.pugetsound.edu/~bryans/Current/Journal_Spring_2006/ARoberts_LeechLattice.pdf int W[12] = { // From Wikipedia: 0x8009F1, 0x4004FA, 0x20027D, 0x10093E, 0x080C9D, 0x040E4E, 0x020F25, 0x010F92, 0x0087C9, 0x0043E6, 0x002557, 0x001AAB}; int r[12] = { // Roberts Page 13 0x800FFD, 0x4000FE, 0x20071E, 0x100B66, 0x080DAA, 0x040ED2, 0x0203CB, 0x010573, 0x0086A7, 0x004997, 0x002A3B, 0x001C4F}; int R[12] = { // Roberts Page 14 0xFF0000, 0xF0F000, 0xCCCC00, 0xAAAA00, 0x999900, 0xA9C0C0, 0x9ACAA0, 0xCA9090, 0x788888, 0x00CCCC, 0x00AAAA, 0x005555}; typedef signed char co; static int weight(int x) {int c=0; while(x){++c; x &= x-1;} return c;} static int vtm(int v, int * m){int p=0; for(int j=0; j<12; ++j) if((v>>j)&1) p ^= m[11-j]; return p;} // Gq is a test of membership in Golay codes. int Gq(int x){return x == vtm(x>>12, W);} static int ew(co * x, int s){int w=0; for(int j=0; j<24; ++j) w=(w<<1)|(x[j]>>s)&1; return w;} // Lq is a test for membership in Leech lattice. int Lq(co * x){ return (ew(x, 0) == (weight(ew(x, 2))&1?0xffffff:0)) && Gq(ew(x, 1));} #if 0 int main(){ for(int j=0; j<12; ++j) assert(Gq(W[j])); assert(Gq(W[3]^W[6])); {co x[24]; for(int i=0; i<24; ++i) x[i] = 0; assert(Lq(x)); x[0] = 8; assert(Lq(x)); x[6] = -8; assert(Lq(x)); x[0] = 0; assert(Lq(x));} {co x[24]; for(int i=0; i<24; ++i) x[i] = i<2?4:0; assert(Lq(x));} {co x[24]; for(int i=0; i<24; ++i) x[i] = i==11?3:-1; assert(Lq(x));} printf("Good\n"); return 0;} #endif