diff --git a/2018/puzzle-01-01.cc b/2018/puzzle-01-01.cc new file mode 100644 index 0000000..cd9cebc --- /dev/null +++ b/2018/puzzle-01-01.cc @@ -0,0 +1,21 @@ +// +// Created by Matthew Gretton-Dann on 01/12/2021. +// + +#include +#include +#include + +using Int = std::int64_t; + +auto main() -> int +{ + Int value{0}; + std::string line; + while (std::getline(std::cin, line)) { + Int incr{std::stoll(line)}; + value += incr; + } + std::cout << "Frequency: " << value << '\n'; + return EXIT_SUCCESS; +} diff --git a/2018/puzzle-01-02.cc b/2018/puzzle-01-02.cc new file mode 100644 index 0000000..a379d72 --- /dev/null +++ b/2018/puzzle-01-02.cc @@ -0,0 +1,35 @@ +// +// Created by Matthew Gretton-Dann on 01/12/2021. +// + +#include +#include +#include +#include +#include + +using Int = std::int64_t; + +auto main() -> int +{ + Int value{0}; + std::string line; + std::set freqs; + std::vector input; + freqs.insert(0); + + while (std::getline(std::cin, line)) { + input.emplace_back(std::stoll(line)); + } + + while (true) { + for (auto incr : input) { + value += incr; + auto [it, success] = freqs.insert(value); + if (!success) { + std::cout << "Double frequency seen at: " << value << '\n'; + return 0; + } + } + } +}