diff --git a/day3/day3Part2 b/day3/day3Part2 new file mode 100755 index 0000000..64acd59 Binary files /dev/null and b/day3/day3Part2 differ diff --git a/day3/day3Part2.broken.cpp b/day3/day3Part2.broken.cpp new file mode 100644 index 0000000..63f5931 --- /dev/null +++ b/day3/day3Part2.broken.cpp @@ -0,0 +1,190 @@ +#include +#include +#include +#include +#include +using namespace std; + +int main (void) +{ + vector> inputValues; + vector> mostCommon; + vector> mostCommonWorking; + vector> leastCommon; + char currentLine[5]; + array currentLineInt; + int mostBitTrue[5] = {}; + int mostBitFalse[5] = {}; + int leastBitTrue[5] = {}; + int leastBitFalse[5] = {}; + int oxygenGenRatingBin[5] = {}; + int coScrubRatingBin[5] = {}; + int oxygenGenRatingDec = 0; + int coScrubRatingDec = 0; + int lifeSupport = 0; + int debugCount = 0; + int vectorSize = 0; + ifstream readFile ("data/testInput.txt", ios::in); + + //file Read + while(readFile >> currentLine) + { + for(int i=0;i<5;i++) + { + if (currentLine[i] == '1') currentLineInt[i] = 1; + else if (currentLine[i] == '0') currentLineInt[i] = 0; + } + inputValues.push_back(currentLineInt); + } + + mostCommon = inputValues; + leastCommon = inputValues; + + + //most Common filter + //Iterate through all bits in line + for(int i=0;i<5;i++) + { + mostCommon = mostCommonWorking; + mostCommonWorking.clear(); + //if there's only one line, leave the loop + if(mostCommon.size() == 1) + { + cout << "Exiting mostCommon loop..." << endl; + break; + } + + //Iterate through all entries in mostCommon, count 1s and 0s + for (int j=0;j mostBitFalse[i]) + { + for(int j=0;j=mostCommon.size();j++) + { + if(mostCommon[j][i] == 1) mostCommonWorking.push_back(mostCommon[i]); + } + } + + //If there are more 0s than 1s, save 0s + if (mostBitFalse[i] > mostBitTrue[i]) + { + for(int j=0;j=mostCommon.size();j++) + { + if(mostCommon[j][i] == 0) mostCommonWorking.push_back(mostCommon[i]); + } + } + cout << "Most Common Working: "; + for(int j=0;j leastBitFalse[i]) + { + for (int j=0;j leastBitTrue[i]) + { + for (int j=0;j -#include -#include -using namespace std; - -int main (void) -{ - char currentLine[12]; - int bitTrue[12] = {}; - int bitFalse[12] = {}; - int gammaRateBin[12] = {}; - int epsilonRateBin[12] = {}; - int gammaRateDec = 0; - int epsilonRateDec = 0; - int powerConsumption; - ifstream readFile ("data/input.txt", ios::in); - - while(readFile >> currentLine) - { - for(int i=0;i<12;i++) - { - if(currentLine[i] == '0') bitFalse[i]++; - else if(currentLine[i] == '1') bitTrue[i]++; - else cout << "Error!!!"; - } - } - - for(int i=0;i<12;i++) - { - if(bitTrue[i] > bitFalse[i]) gammaRateBin[i] = 1; - else epsilonRateBin[i] = 1; - } - - for(int i=0;i<12;i++) - { - gammaRateDec += gammaRateBin[i] * pow(2,11-i); - epsilonRateDec += epsilonRateBin[i] * pow(2,11-i); - } - powerConsumption = gammaRateDec * epsilonRateDec; - cout << "\nPower Consumption: " << powerConsumption; - return 0; -}