From 204146e91d1ff8b625c9c91a5a93e85c8408c801 Mon Sep 17 00:00:00 2001 From: kaiwu Date: Wed, 8 Feb 2023 17:00:53 +0800 Subject: 2017 day13 --- src/2017/day13/aoc.cpp | 13 ++++++++++++- src/2017/day13/aoc.h | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/2017/day13/aoc.cpp b/src/2017/day13/aoc.cpp index e112b3e..e3cf129 100644 --- a/src/2017/day13/aoc.cpp +++ b/src/2017/day13/aoc.cpp @@ -2,5 +2,16 @@ namespace aoc2017 { -std::pair day13(line_view) { return {0, 0}; } +std::pair day13(line_view file) { + std::vector vs; + per_line(file, [&vs](line_view lv) { + vs.emplace_back(lv); + return true; + }); + + // for (auto& s: vs) { + // s.print(); + // } + return {0, 0}; +} } // namespace aoc2017 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 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 day13(line_view); -} +} // namespace aoc2017 -- cgit v1.2.3