-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_08b.cpp
50 lines (46 loc) · 1.14 KB
/
day_08b.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
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <vector>
int main(int argc, char* argv[]) {
// Get input
std::string input = "../input/day_08_input";
if (argc > 1) {
input = argv[1];
}
std::ifstream file(input);
std::string line;
std::getline(file, line);
std::vector<int> image;
image.reserve(line.size());
for (const auto c : line) {
image.emplace_back(c - '0');
}
// Solve
constexpr int n_rows = 6;
constexpr int n_cols = 25;
constexpr int pixels_in_layer = n_rows * n_cols;
std::array<int, pixels_in_layer> final_image;
size_t index = 0;
size_t min_index = 0;
size_t n_zeros = pixels_in_layer;
std::fill(std::begin(final_image), std::end(final_image), 2);
for (int i = 0; i < pixels_in_layer; i++) {
auto it = std::begin(image) + i;
while (it < std::end(image)) {
if (*it != 2) {
final_image[i] = *it;
break;
}
it += pixels_in_layer;
}
}
for (int i = 0; i < n_rows; i++) {
for (int j = 0; j < n_cols; j++) {
std::cout << final_image[i * n_cols + j] << ' ';
}
std::cout << '\n';
}
return 0;
}