-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathday_05b.cpp
More file actions
30 lines (29 loc) · 818 Bytes
/
day_05b.cpp
File metadata and controls
30 lines (29 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <unordered_set>
#include <vector>
int main(int argc, char* argv[]) {
const std::string input = (argc > 1) ? argv[1] : "../input/day_05_input" ;
std::ifstream file(input);
std::string line;
std::size_t n_steps = 0;
int pointer = 0;
std::vector<int> instructions;
while(std::getline(file, line)) {
instructions.emplace_back(std::stoi(line));
}
while (pointer >= 0 && pointer < instructions.size()) {
const auto prev_pointer = pointer;
pointer += instructions[pointer];
if (instructions[prev_pointer] >= 3) {
instructions[prev_pointer]--;
} else {
instructions[prev_pointer]++;
}
n_steps++;
}
std::cout << n_steps << '\n';
return 0;
}