diff options
Diffstat (limited to 'src/2017/day13/aoc.h')
-rw-r--r-- | src/2017/day13/aoc.h | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/2017/day13/aoc.h b/src/2017/day13/aoc.h index 5baa78a..5e46b4f 100644 --- a/src/2017/day13/aoc.h +++ b/src/2017/day13/aoc.h @@ -3,5 +3,40 @@ #include <vector> namespace aoc2017 { + +struct scanner { + int depth = 0; + int range = 0; + + void get_number(const char** pp, int* d) { + const char* p = *pp; + while (*p >= '0' && *p <= '9') { + *d = *d * 10 + *p - '0'; + p++; + } + *pp = p; + } + + void print() const noexcept { + printf("%d %d\n", depth, range); + } + + int at_level(int t) const noexcept { + return 0; + } + + scanner(line_view lv) { + int* ds[] = {&depth, &range}; + int i{0}; + const char* p = lv.line; + while (p < lv.line + lv.length) { + if (*p >= '0' && *p <= '9') { + get_number(&p, ds[i++]); + } + p++; + } + } +}; + std::pair<int64_t, int64_t> day13(line_view); -} +} // namespace aoc2017 |