-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
47 lines (41 loc) · 1.13 KB
/
main.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "file.h"
#include <iostream>
#include <vector>
namespace aoc2017_day05 {
int part_1(std::string_view path) {
std::vector<int> input = file::readFileAsArrayInt(path);
int start = 0;
int steps = 0;
while (start < input.size()) {
int newStart = start + input[start];
input[start]++;
start = newStart;
steps++;
}
return steps;
}
int part_2(std::string_view path) {
std::vector<int> input = file::readFileAsArrayInt(path);
int start = 0;
int steps = 0;
while (start < input.size()) {
int newStart = start + input[start];
if (input[start] >= 3) {
input[start]--;
}
else {
input[start]++;
}
start = newStart;
steps++;
}
return steps;
}
}
#ifndef TESTING
int main() {
std::cout << "Part 1: " << aoc2017_day05::part_1("../2017/day05/input.in") << std::endl;
std::cout << "Part 2: " << aoc2017_day05::part_2("../2017/day05/input.in") << std::endl;
return 0;
}
#endif