Skip to content

Commit 6f7d1e4

Browse files
committed
Parse board and instructions
1 parent 21a9a09 commit 6f7d1e4

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

day15/src/day15.cpp

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
#include <iostream>
2+
#include <fstream>
3+
#include <string>
4+
5+
int main(int argc, char *argv[]) {
6+
if (argc == 1) {
7+
std::cerr << "Usage: " << argv[0] << " <path to input>" << std::endl;
8+
return 1;
9+
}
10+
11+
std::vector<std::string> board;
12+
std::string instructions;
13+
14+
{
15+
std::ifstream file;
16+
file.open(argv[1]);
17+
18+
bool in_board = true;
19+
for (std::string line; std::getline(file, line);) {
20+
if (in_board) {
21+
if (line.empty()) {
22+
in_board = false;
23+
} else {
24+
board.push_back(line);
25+
}
26+
} else {
27+
instructions += line;
28+
}
29+
}
30+
}
31+
32+
for (const std::string &line : board) {
33+
std::cout << "Line: " << line << std::endl;
34+
}
35+
std::cout << "Instructions: " << instructions << std::endl;
236

3-
int main() {
4-
std::cout << "Hello" << std::endl;
537
return 0;
638
}

0 commit comments

Comments
 (0)