From 4ecdf3e6f39d7e218e24dcd53cdaf0b681a87186 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Thu, 3 Dec 2020 04:23:43 -0600 Subject: [PATCH] chore: format code --- day_3/main.cpp | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/day_3/main.cpp b/day_3/main.cpp index 8609abf..4fa96cf 100644 --- a/day_3/main.cpp +++ b/day_3/main.cpp @@ -5,37 +5,36 @@ int calcNumOfEncounteredTrees( - const std::vector>& world, + const std::vector> &world, const std::pair dimensions, std::pair slope - ) { - int treeCount = 0; - int x = 0; +) { + int treeCount = 0; + int x = 0; - for (int y = 0; y < dimensions.second; y += slope.second) { - if (!world[y][ x % dimensions.first]) treeCount++; - x += slope.first; - } + for (int y = 0; y < dimensions.second; y += slope.second) { + if (!world[y][x % dimensions.first]) treeCount++; + x += slope.first; + } - return treeCount; + return treeCount; } - -void part1(const std::vector>& world, const int width, const int height) { +void part1(const std::vector> &world, const int width, const int height) { const int RISE = 1; const int RUN = 3; - int count = calcNumOfEncounteredTrees(world, { width, height }, { RISE, RUN }); + int count = calcNumOfEncounteredTrees(world, {width, height}, {RISE, RUN}); std::cout << "(P1) Number of trees: " << count << std::endl; } -void part2(const std::vector>& world, const int width, const int height) { - int count1 = calcNumOfEncounteredTrees(world, { width, height }, { 1, 1 }); - int count2 = calcNumOfEncounteredTrees(world, { width, height }, { 3, 1 }); - int count3 = calcNumOfEncounteredTrees(world, { width, height }, { 5, 1 }); - int count4 = calcNumOfEncounteredTrees(world, { width, height }, { 7, 1 }); - int count5 = calcNumOfEncounteredTrees(world, { width, height }, { 1, 2 }); +void part2(const std::vector> &world, const int width, const int height) { + int count1 = calcNumOfEncounteredTrees(world, {width, height}, {1, 1}); + int count2 = calcNumOfEncounteredTrees(world, {width, height}, {3, 1}); + int count3 = calcNumOfEncounteredTrees(world, {width, height}, {5, 1}); + int count4 = calcNumOfEncounteredTrees(world, {width, height}, {7, 1}); + int count5 = calcNumOfEncounteredTrees(world, {width, height}, {1, 2}); uint64_t product = count1 * count2 * count3 * count4 * count5; std::cout << "(P2) Product of number of trees: " << product << std::endl; @@ -43,14 +42,14 @@ void part2(const std::vector>& world, const int width, const i int main() { - std::ifstream input { "../input.txt" }; + std::ifstream input{"../input.txt"}; std::vector> world; std::optional maybeWidth = std::nullopt; int lineCount = 0; std::string line; - while(std::getline(input, line)) { - if (!maybeWidth.has_value()) maybeWidth = { line.length() }; + while (std::getline(input, line)) { + if (!maybeWidth.has_value()) maybeWidth = {line.length()}; std::vector row; for (char c : line) row.push_back(c == '.');