diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1cfd981 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*/** +!*/*.cpp \ No newline at end of file diff --git a/Day1/part1.cpp b/Day1/part1.cpp new file mode 100644 index 0000000..7f52b3e --- /dev/null +++ b/Day1/part1.cpp @@ -0,0 +1,25 @@ +#include +#include + +int main(int argc, char* argv[]) +{ + std::string line; + int total = 0; + int max = 0; + while(std::getline(std::cin, line)) + { + if (0 == line.size()) + { + if (total > max) + { + max = total; + } + total = 0; + } + else + { + total += stoi(line); + } + } + std::cout << max << std::endl; +} \ No newline at end of file diff --git a/Day1/part2.cpp b/Day1/part2.cpp new file mode 100644 index 0000000..e01faa8 --- /dev/null +++ b/Day1/part2.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +int main(int argc, char* argv[]) +{ + std::string line; + int total = 0; + std::vector sums; + while(std::getline(std::cin, line)) + { + if (0 == line.size()) + { + sums.push_back(total); + total = 0; + } + else + { + total += stoi(line); + } + } + + std::sort(sums.begin(), sums.end(), std::greater<>()); + std::cout << sums[0] + sums[1] + sums[2] << std::endl; +} \ No newline at end of file diff --git a/README.md b/README.md index ada0e90..c32d2fb 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,6 @@ Advent of Code for 2022 -## How to contribute +# Branch format -To contribute to the Advent of Code 2022, please pull master and create a branch with your name. - -Recommended folder structure is `{Day}\{Language}\{Part}` - -## Tips - -It is recommended to include small document on how the program works and how to compile & run the program. \ No newline at end of file +Uploading code files at partX.cpp in each days folder. Compile the part with `g++ partX.cpp -o partX`. Download your input file as `inptuX` and run the program with `./partX < inputX`. \ No newline at end of file