Bit Manipulation Brain Teaser
softwaresimply.blogspot.com
softwaresimply.blogspot.com
const uint numBits = 3*numPieces;
const u64 lowBits = ((1ULL << numBits)-1);
const u64 highBits = lowBits << numBits;
// Flip around horizontal axis
flippedIndex = index ^ 4;
// Flip around vertical axis
flippedIndex = index ^ 2;
// Flip around diagonal axis
flippedIndex = (index & highBits) | ((index & lowBits) ^ lowBits) ^ ((index & highBits) >> numBits))
Edit: my last one ain't right const uint numBits = 3*numPieces;
const u64 lowBits = ((1ULL << numBits)-1);
const u64 highBits = lowBits << numBits;
const u64 allFours = 04040404040404040404;
const u64 allTwos = 02020202020202020202;
// Flip around horizontal axis
flippedIndex = index ^ (allFours & lowBits);
// Flip around vertical axis
flippedIndex = index ^ (allTwos & lowBits);
Is my fix for the first two, but, as you point out, they're significantly easier.The patterns are pretty neat, but I can't figure out how they result in any sort of rule for diagonal flipping.