diff --git a/2017/puzzle-05-01.cc b/2017/puzzle-05-01.cc new file mode 100644 index 0000000..223713d --- /dev/null +++ b/2017/puzzle-05-01.cc @@ -0,0 +1,26 @@ +#include +#include +#include + +using Int = long; + +auto main() -> int +{ + std::vector jumps; + std::string line; + while (std::getline(std::cin, line) && !line.empty()) { + jumps.push_back(std::stol(line)); + } + + Int pc{0}; + unsigned steps{0}; + while (pc >= 0 && pc < jumps.size()) { + ++steps; + auto delta = jumps[pc]; + ++(jumps[pc]); + pc += delta; + } + + std::cout << "Steps: " << steps << '\n'; + return 0; +} diff --git a/2017/puzzle-05-02.cc b/2017/puzzle-05-02.cc new file mode 100644 index 0000000..16c9b5f --- /dev/null +++ b/2017/puzzle-05-02.cc @@ -0,0 +1,31 @@ +#include +#include +#include + +using Int = long; + +auto main() -> int +{ + std::vector jumps; + std::string line; + while (std::getline(std::cin, line) && !line.empty()) { + jumps.push_back(std::stol(line)); + } + + Int pc{0}; + unsigned steps{0}; + while (pc >= 0 && pc < jumps.size()) { + ++steps; + auto delta = jumps[pc]; + if (delta >= 3) { + --(jumps[pc]); + } + else { + ++(jumps[pc]); + } + pc += delta; + } + + std::cout << "Steps: " << steps << '\n'; + return 0; +}