diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-03-17 08:55:03 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-03-17 08:55:03 +0800 |
commit | 2e87804114b6c1e732ce002dc9a5f74db43e4cee (patch) | |
tree | ce2be15532c317c166ad8bf1489d98099a2a182b /src | |
parent | 4747911566e69b1d95e88bb5955ffbeddfae6a08 (diff) | |
download | advent-of-code-2e87804114b6c1e732ce002dc9a5f74db43e4cee.tar.gz advent-of-code-2e87804114b6c1e732ce002dc9a5f74db43e4cee.zip |
grid
Diffstat (limited to 'src')
-rw-r--r-- | src/2015/day6/aoc.h | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/2015/day6/aoc.h b/src/2015/day6/aoc.h index b68ef18..96fecca 100644 --- a/src/2015/day6/aoc.h +++ b/src/2015/day6/aoc.h @@ -6,8 +6,7 @@ namespace aoc2015 { template <size_t N> struct grid { - static_assert(N > 0 && ((N & (N - 1)) == 0), "N must be power of 2"); - constexpr static size_t size = N * N / 64; + constexpr static size_t size = N * N / 64 + 1; uint64_t pool[size] = {0}; @@ -17,29 +16,29 @@ struct grid { }; void set(int x, int y) { - uint64_t p = x * N + y; + uint64_t p = y * N + x; uint64_t r = p >> 6; uint64_t c = p & 63; uint64_t& byte = pool[r]; - uint64_t mask = 1 << c; + uint64_t mask = 1ll << c; byte |= mask; } void reset(int x, int y) { - uint64_t p = x * N + y; + uint64_t p = y * N + x; uint64_t r = p >> 6; uint64_t c = p & 63; uint64_t& byte = pool[r]; - uint64_t mask = ~(1 << c); + uint64_t mask = ~(1ll << c); byte &= mask; } void toggle(int x, int y) { - uint64_t p = x * N + y; + uint64_t p = y * N + x; uint64_t r = p >> 6; uint64_t c = p & 63; uint64_t& byte = pool[r]; - uint64_t mask = 1 << c; + uint64_t mask = 1ll << c; byte ^= mask; } |