diff options
Diffstat (limited to 'src/2022/day14/aoc.cpp')
-rw-r--r-- | src/2022/day14/aoc.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/2022/day14/aoc.cpp b/src/2022/day14/aoc.cpp index a96877d..00bc0c8 100644 --- a/src/2022/day14/aoc.cpp +++ b/src/2022/day14/aoc.cpp @@ -3,6 +3,29 @@ namespace aoc2022 { rock::three rock::t3; +int fall1(cave& cv) { + bool fall{true}; + int n{0}; + while(fall) { + auto p = cv.drop(cv.to({500,0})); + rock::pos ns[] = {{p.x, p.y + 1}, {p.x - 1, p.y + 1}, {p.x + 1, p.y + 1}}; + for (int i = 0; i < 3; i++) { + if (!cv.valid(ns[i])) { + fall = false; + } + } + if (fall) { + cv.get(p) = 'o'; + n++; + } + } + return n; +} + +int fall2(cave& cv) { + return 0; +} + std::pair<int, int> day14(line_view file) { std::vector<rock> rocks; per_line(file, [&rocks](line_view lv){ @@ -17,8 +40,8 @@ std::pair<int, int> day14(line_view file) { cv.mark(r); } - // cv.print(); - return {0, 0}; + cave cv2{cv}; + return {fall1(cv), fall2(cv2)}; } } |