Excellent solution! This code only scan the table once.
Just a little explanation about cube transfer:
the reason to use (i/3)*3 is that,
when i = 0,1,2, the value of this equation is 0,
when i = 3,4,5, the value of this equation is 3,
when i = 6,7,8, the value of this equation is 6.
Division can cut i into 3 slots, plus j, it pinpoints the location in Boolean 2D array.