Add 2017 day 5 puzzles
This commit is contained in:
26
2017/puzzle-05-01.cc
Normal file
26
2017/puzzle-05-01.cc
Normal 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
31
2017/puzzle-05-02.cc
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user