#include #include #include using namespace std; int main() { cout << "Advent of Code 2021 - Day 3 Part 1" << endl; unsigned int gamma = 0; unsigned int epsilon = 0; vector> inputBits; ifstream filein("input"); for(string line; getline(filein, line);) { vector bits; for(int i = 0; i < 12; i++) { if (line[i] == '1') { bits.push_back(1); } else { bits.push_back(0); } } inputBits.push_back(bits); } for(int x = 0; x < 12; x++) { int greater = 0; for(int i = 0; i < inputBits.size(); i++) { if(inputBits[i][x] == 1) { greater++; } } if(greater > (inputBits.size() / 2)) { gamma |= 1UL << 11 - x; } else { epsilon |= 1UL << 11 - x; } } cout << gamma << endl; cout << epsilon << endl; cout << gamma * epsilon << endl; return 0; }