From 5533ef2b2549f9a4cae3697c2db4aff5511174b2 Mon Sep 17 00:00:00 2001 From: limb Date: Fri, 3 Dec 2021 20:17:53 +0000 Subject: [PATCH] Day 3 Part 1 --- day3/part1/main.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) 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