-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoC5.cpp
66 lines (52 loc) · 954 Bytes
/
AoC5.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "lib.h"
#include <vector>
using std::vector;
#include <iostream>
using std::cout;
void part1(vector<int> in)
{
int position = 0;
int steps = 0;
while (position >= 0 && position < in.size()) {
int toJump = in[position];
in[position]++;
position += toJump;
steps++;
}
cout << "Part 1 steps: " << steps << "\n";
}
void part2(vector<int> in)
{
int position = 0;
int steps = 0;
while (position >= 0 && position < in.size()) {
int toJump = in[position];
if (toJump >= 3)
{
in[position]--;
}
else
{
in[position]++;
}
position += toJump;
steps++;
}
cout << "Part 2 steps: " << steps << "\n";
}
int _tmain(int argc, _TCHAR* argv[])
{
try{
vector<string> results = readFileAsLines("in_5.txt");
vector<int> res_i;
for (unsigned int i = 0 ; i!=results.size() ; i++) {
res_i.push_back(stoi(results[i]));
}
part1(res_i);
part2(res_i);
}
catch (FileReadException &e)
{
}
return 0;
}