diff --git a/2017/puzzle-02-01.cc b/2017/puzzle-02-01.cc new file mode 100644 index 0000000..150cf05 --- /dev/null +++ b/2017/puzzle-02-01.cc @@ -0,0 +1,29 @@ +#include +#include +#include + +auto main() -> int +{ + std::string line; + std::uint64_t checksum{0}; + while (std::getline(std::cin, line) && !line.empty()) { + std::vector nums; + std::size_t idx{0}; + while (idx < line.size()) { + if (std::iswspace(line[idx]) == 1) { + ++idx; + continue; + } + + std::size_t end{0}; + nums.push_back(std::stoul(line.substr(idx), &end)); + idx += end; + } + + auto [min, max] = std::minmax_element(nums.begin(), nums.end()); + checksum += *max - *min; + } + + std::cout << "Checksum: " << checksum << '\n'; + return 0; +} diff --git a/2017/puzzle-02-02.cc b/2017/puzzle-02-02.cc new file mode 100644 index 0000000..fe94172 --- /dev/null +++ b/2017/puzzle-02-02.cc @@ -0,0 +1,33 @@ +#include +#include +#include + +auto main() -> int +{ + std::string line; + std::uint64_t checksum{0}; + while (std::getline(std::cin, line) && !line.empty()) { + std::vector nums; + std::size_t idx{0}; + while (idx < line.size()) { + if (std::iswspace(line[idx]) == 1) { + ++idx; + continue; + } + + std::size_t end{0}; + nums.push_back(std::stoul(line.substr(idx), &end)); + idx += end; + } + + for (auto n1 : nums) { + for (auto n2 : nums) { + if (n1 != n2 && n1 % n2 == 0) + checksum += n1 / n2; + } + } + } + + std::cout << "Checksum: " << checksum << '\n'; + return 0; +}