Magic squares of doubly even order: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Meh. tried to be cute and ended up wrong. undo) |
m (→{{header|Java}}: small changes) |
||
Line 186: | Line 186: | ||
// pattern of count-up vs count-down zones |
// pattern of count-up vs count-down zones |
||
int bits = |
int bits = 0b1001_0110_0110_1001; |
||
int size = n * n; |
int size = n * n; |
||
int mult = n / 4; // how many multiples of 4 |
int mult = n / 4; // how many multiples of 4 |
||
Line 194: | Line 194: | ||
for (int r = 0, i = 0; r < n; r++) { |
for (int r = 0, i = 0; r < n; r++) { |
||
for (int c = 0; c < n; c++, i++) { |
for (int c = 0; c < n; c++, i++) { |
||
int |
int bitPos = c / mult + (r / mult) * 4; |
||
result[r][c] = (bits & (1 << |
result[r][c] = (bits & (1 << bitPos)) != 0 ? i + 1 : size - i; |
||
} |
} |
||
} |
} |