Add 2017 day 5 puzzles

This commit is contained in:
2021-12-13 16:17:05 +00:00
parent 3e77d0aacc
commit 204f9fc02a
2 changed files with 57 additions and 0 deletions

26
2017/puzzle-05-01.cc Normal file
View File

@@ -0,0 +1,26 @@
#include <iostream>
#include <string>
#include <vector>
using Int = long;
auto main() -> int
{
std::vector<Int> 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;
}

31
2017/puzzle-05-02.cc Normal file
View File

@@ -0,0 +1,31 @@
#include <iostream>
#include <string>
#include <vector>
using Int = long;
auto main() -> int
{
std::vector<Int> 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;
}