-
Notifications
You must be signed in to change notification settings - Fork 0
/
day5.cpp
42 lines (39 loc) · 855 Bytes
/
day5.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
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
const char FILENAME[] = "input.txt";
const int MAX_INSTRUCTIONS = 1000;
int main()
{
ifstream stream;
stream.open(FILENAME);
if (stream.fail())
{
cout << "Couldn't open file" << endl;
exit(1);
}
int instructions[MAX_INSTRUCTIONS];
int nInstructions = 0;
int i;
while (stream >> i)
{
if (nInstructions <= MAX_INSTRUCTIONS)
instructions[nInstructions] = i;
nInstructions++;
}
stream.close();
int steps = 0;
int n = 0;
while (n < nInstructions)
{
int oldN = n;
n += instructions[n];
if (instructions[oldN] >= 3)
instructions[oldN]--;
else
instructions[oldN]++;
steps++;
}
cout << steps << endl;
}