-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_10a.cpp
42 lines (38 loc) · 1 KB
/
day_10a.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 <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
int main() {
std::ifstream file{"../input/day_10_input"};
std::vector<int> adapter_joltages;
int adapter_joltage;
while (file >> adapter_joltage) {
adapter_joltages.push_back(adapter_joltage);
}
std::sort(std::begin(adapter_joltages), std::end(adapter_joltages));
int n_del_1 = 0;
int n_del_2 = 0;
int n_del_3 = 0;
for (int i = 0; i < adapter_joltages.size() - 1; ++i) {
const int del = adapter_joltages[i + 1] - adapter_joltages[i];
if (del == 1) {
++n_del_1;
} else if (del == 2) {
++n_del_2;
} else if (del == 3) {
++n_del_3;
}
}
// Difference between lowest adapter and port
if (adapter_joltages[0] == 1) {
++n_del_1;
} else if (adapter_joltages[0] == 2) {
++n_del_2;
} else if (adapter_joltages[0] == 3) {
++n_del_3;
}
// Difference between last adapter and device
++n_del_3;
std::cout << n_del_1 * n_del_3 << '\n';
return n_del_1 * n_del_3;
}