From 204f9fc02aaa0424448865ae047cdbbb056ea78b Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Mon, 13 Dec 2021 16:17:05 +0000 Subject: [PATCH] Add 2017 day 5 puzzles --- 2017/puzzle-05-01.cc | 26 ++++++++++++++++++++++++++ 2017/puzzle-05-02.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 2017/puzzle-05-01.cc create mode 100644 2017/puzzle-05-02.cc 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; +}