-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3a.cpp
45 lines (42 loc) · 1001 Bytes
/
day3a.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
#include "utils.hpp"
int value_getter(char &input)
{
if (isupper(input))
{
return (int(input) - 'A' + 26);
}
else
{
return (int(input) - 'a');
}
}
int main(int argc, char *argv[])
{
auto input = read_input("day3_input");
static int data_len = 52;
int total_value = 0;
for (auto &&x : input)
{
bool c1[data_len] = {};
bool c2[data_len] = {};
auto compartment_size = x.length() / 2;
auto c_1_letters = x.substr(0, compartment_size);
auto c_2_letters = x.substr(compartment_size, compartment_size);
for (auto &&y : c_1_letters)
{
c1[value_getter(y)] = true;
}
for (auto &&z : c_2_letters)
{
c2[value_getter(z)] = true;
}
for (int i = 0; i < data_len; i++)
{
if (c1[i] && c2[i])
{
total_value += (i + 1);
}
}
}
std::cout << total_value << "\n";
}