diff --git a/day3/part1/main.cpp b/day3/part1/main.cpp index fe9d0f9..88ca224 100644 --- a/day3/part1/main.cpp +++ b/day3/part1/main.cpp @@ -7,8 +7,8 @@ using namespace std; int main() { cout << "Advent of Code 2021 - Day 3 Part 1" << endl; - unsigned char gamma[12] = {0}; - unsigned char epsilon[12] = {0}; + unsigned int gamma = 0; + unsigned int epsilon = 0; vector> inputBits; @@ -36,22 +36,15 @@ int main() { } if(greater > (inputBits.size() / 2)) { - gamma[x] = 1; - epsilon[x] = 0; + gamma |= 1UL << 11 - x; } else { - gamma[x] = 0; - epsilon[x] = 1; + epsilon |= 1UL << 11 - x; } } - int asd = 0; - - for(int x = 0; x < 12; x++) { - asd = asd << (int)gamma[x]; - } - cout << asd << endl; - + cout << gamma << endl; cout << epsilon << endl; + cout << gamma * epsilon << endl; return 0; } \ No newline at end of file