aboutsummaryrefslogtreecommitdiff
path: root/src/2016/day8/aoc.h
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-05-09 18:22:21 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-05-09 18:22:21 +0800
commit2e5392ba4c93d5b9d5eb2a560418b13e76f2059f (patch)
tree5e3f4e40196eea0778a34a358f20ab8a1b396caf /src/2016/day8/aoc.h
parentdca2e70a10b7928c8a73f73d5dc7ef74f9001005 (diff)
downloadadvent-of-code-2e5392ba4c93d5b9d5eb2a560418b13e76f2059f.tar.gz
advent-of-code-2e5392ba4c93d5b9d5eb2a560418b13e76f2059f.zip
2016 day8
Diffstat (limited to 'src/2016/day8/aoc.h')
-rw-r--r--src/2016/day8/aoc.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/2016/day8/aoc.h b/src/2016/day8/aoc.h
index d92a8f7..2313bc9 100644
--- a/src/2016/day8/aoc.h
+++ b/src/2016/day8/aoc.h
@@ -7,9 +7,17 @@ template <size_t W, size_t H>
struct grid {
char cells[W * H] = {0};
+ int count() const noexcept {
+ int total{0};
+ for (size_t i = 0; i < ARRAY_SIZE(cells); i++) {
+ total += int(cells[i] == 1);
+ }
+ return total;
+ }
+
void print() {
for (size_t i = 0; i < ARRAY_SIZE(cells); i++) {
- printf("%d", cells[i]);
+ printf("%s", cells[i] == 0 ? "." : "#");
if (i % W == W - 1) {
printf("\n");
}