// This is the original code posted on IOTA's Discord. int ref1(int i, int x, int y) { return i % y + ((((i / y) + x) % 3) + (i / (y * 3)) * 3) * y; } // A simplified version posted by someone on IOTA's Discord (not exactly sure // who posted it first). int ref2(int i, int x, int y) { return i + (((i / y) + x) % 3 - ((i / y) % 3)) * y; }