Skip to content

Commit

Permalink
2023: day 9 part 2 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
yut23 committed Dec 10, 2023
1 parent 0ac05ab commit d77c8bd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions 2023/src/day09.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main(int argc, char **argv) {

// read file line-by-line
std::string line;
int part_1 = 0;
int part_1 = 0, part_2 = 0;
while (std::getline(infile, line)) {
using namespace aoc::day09;
std::stack<std::vector<int>> diffs;
Expand All @@ -28,14 +28,18 @@ int main(int argc, char **argv) {
diffs.push(diff(diffs.top()));
}
diffs.pop();
int next = 0;
int next = 0, prev = 0;
while (!diffs.empty()) {
next += diffs.top().back();
next = diffs.top().back() + next;
prev = diffs.top().front() - prev;
diffs.pop();
}
part_1 += next;
part_2 += prev;
}

std::cout << part_1 << "\n";
std::cout << part_2 << "\n";

return 0;
}

0 comments on commit d77c8bd

Please sign in to comment.