-
Notifications
You must be signed in to change notification settings - Fork 9
/
day_02a.cpp
43 lines (40 loc) · 1.07 KB
/
day_02a.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
#include <array>
#include <fstream>
#include <iostream>
#include <string>
int main(int argc, char* argv[]) {
std::string input = "../input/day_02_input";
if (argc > 1) {
input = argv[1];
}
std::ifstream file(input);
std::string instructions;
constexpr int dim = 3;
std::array<std::array<int, dim>, dim> keypad{
std::array<int, 3>{1,2,3},
std::array<int, 3>{4,5,6},
std::array<int, 3>{7,8,9}
};
int current_x = 1;
int current_y = 1;
while(std::getline(file, instructions)) {
for (const auto instruction : instructions) {
if (instruction == 'U') {
if (current_y != 0) current_y -= 1;
}
else if (instruction == 'R') {
if (current_x != 2) current_x += 1;
}
else if (instruction == 'D') {
if (current_y != 2) current_y += 1;
}
else if (instruction == 'L') {
if (current_x != 0) current_x -= 1;
}
// std::cout << keypad[current_y][current_x];
}
std::cout << keypad[current_y][current_x];
}
std::cout << '\n';
return 0;
}