diff --git a/day3/data/input.txt b/day3/data/input.txt new file mode 100644 index 0000000..69e47f6 --- /dev/null +++ b/day3/data/input.txt @@ -0,0 +1,1000 @@ +000000011010 +011001111011 +100101011101 +000110000110 +101010001010 +010010000011 +011001111001 +100111000000 +011101011010 +000000110001 +101110111100 +111110100001 +000000001111 +001011111111 +101011001111 +101000101010 +110111010001 +000010011111 +000101001011 +101111001001 +100000000100 +010100010100 +100110001110 +101011101110 +111100101101 +000101000001 +001110000011 +111010110001 +101000101000 +011011000101 +000001100100 +101001011101 +001111111111 +101001001101 +100100100001 +101111000100 +000110101000 +001100011001 +101111101000 +101010110000 +110100010001 +101110101100 +010101100100 +011101100110 +101000011011 +101110101011 +110100001100 +100111000001 +010000100000 +111010110010 +111110100111 +001101110111 +001001100100 +000110100100 +011100110010 +100110001100 +011011110110 +110001011100 +101111001111 +110011011101 +111001100110 +110110011001 +111011000000 +000101101011 +111110101110 +000100011000 +000001000001 +010110000011 +000100011100 +011000110000 +101011010101 +100101110101 +110001010010 +101111001101 +101110011010 +101110000010 +010001111010 +100000111111 +000000010011 +100010111011 +000110100000 +101111000101 +001110011101 +100011010010 +100001011101 +011100101100 +111100010010 +111011011110 +010010000110 +010100001011 +011000100010 +100011001000 +011001101001 +110110010001 +111110001001 +000111101100 +100111000011 +111011110100 +101000000010 +011000110101 +101010110101 +110110000011 +111101000110 +010000100110 +000110101010 +111100110110 +111000011101 +010001011101 +101011011000 +101000101110 +110101010001 +000001110011 +110010001110 +110110000101 +110111111001 +110001000101 +001101010011 +010100011100 +111011100100 +101010001011 +001011101011 +101100010001 +010100000000 +110100000100 +010011111111 +101010010100 +111101000101 +000011000011 +001111100000 +010110101110 +001010110010 +000111100001 +101000101101 +111101110010 +000000101011 +110010000111 +001111100110 +000100001110 +110101101000 +000010100001 +000111010011 +010110001101 +111110011001 +011011111001 +000011010011 +001111000000 +011000010001 +000100011011 +110011111011 +001011101101 +010111011111 +001001110111 +100110100011 +000001110100 +000010011000 +110001101000 +000001100111 +011110100000 +110000001000 +110000001110 +000010001100 +000011100010 +101100111101 +101000000011 +110011001010 +110100110000 +100101001010 +111000111011 +100011001010 +111111111110 +111100000011 +011101110101 +010100001111 +010110010000 +000011010100 +011111010001 +111011000010 +111110000110 +101100101101 +010111011001 +001001111100 +001101010000 +011000100000 +001011111110 +100010101111 +001100010101 +001000001111 +110001010011 +000000011100 +011100010001 +000111100101 +010000010110 +000001111100 +010010110111 +110101001100 +001011001100 +111111011100 +111001100101 +001010010000 +101100101001 +101100110011 +011100111100 +110001110100 +101000101111 +110011111001 +011101000010 +100001111001 +010101111101 +101101010010 +110001011010 +110100100001 +011011110111 +101110110000 +110111001001 +000011110100 +101000110001 +011110110111 +011011101001 +101011101001 +100001111011 +101001010011 +110000010010 +001011110110 +110001011011 +101100100001 +001010000101 +101011000100 +000111110100 +011010000010 +110000011001 +010001011110 +001000100011 +010000111010 +011010111000 +000001110010 +010010011111 +100100010000 +001000000110 +100001110111 +000100010000 +000010110000 +010100111101 +100001100111 +100101101011 +000010111010 +010110111100 +100101010110 +001000101000 +011101101011 +000111101001 +001000010101 +101011010001 +001110101100 +010010100100 +101101101100 +000010111101 +000100111000 +100010110000 +001100101111 +111110000011 +001101101100 +110101001111 +110010101010 +011111000101 +111001111101 +000011001101 +000000011001 +010001110001 +001001010011 +110101110101 +011011110010 +111010110111 +011000011110 +111110011110 +110001001101 +010110100100 +011100000101 +000111110111 +101110100010 +000000011000 +011101010011 +001111100001 +110010010101 +101001001100 +000111100011 +101111100011 +001100010001 +110001100101 +011001101100 +000011000010 +000001111000 +110010001100 +110011010011 +010111100001 +101101101101 +010010100110 +010001101100 +111100100001 +001000001001 +110110101000 +000011000001 +001001001011 +001101100100 +100011111110 +100101110110 +001100010000 +100111100111 +010111100111 +110011101111 +010001101010 +011010011111 +001011000110 +010001100000 +111001010011 +010011100111 +101000111110 +110110110110 +000011111001 +101011100110 +000010011110 +010001111101 +100111010101 +100111001001 +100000010011 +000011111010 +110010100010 +101101000001 +111000001010 +011111101100 +001100001101 +000100010011 +010110011110 +001110001011 +101110011111 +011111000010 +110101001000 +000000110100 +110110101101 +010111110100 +110000000001 +100011100001 +100000010110 +010100100110 +100111111001 +000110111110 +000000110000 +110001110101 +101110110110 +101011110101 +110100110010 +010000001010 +110001111111 +000110101101 +111100010110 +110011100011 +110000000111 +110011011011 +111111001110 +111110111001 +110001110110 +001101000000 +001011111001 +110001001010 +001000010100 +001011110001 +000000010000 +111111000001 +110010000110 +111010011111 +100100100100 +000000000101 +100001010000 +110101110111 +001011111100 +100111101100 +100011110110 +110110111100 +001001010001 +011100111101 +110110001101 +111100001011 +000000100100 +111101101010 +111001111100 +010101110011 +101010100110 +100001000101 +100110011101 +101101000100 +100000011011 +001001101000 +001010011110 +100010011011 +011100010111 +011101000111 +111100101110 +100100000111 +100101110001 +100000011101 +001000011001 +010101100110 +101001101010 +100011110000 +101010100000 +111000101100 +111000101110 +101000100001 +100110000100 +010010110011 +111001101011 +011000000100 +010100001000 +010001101001 +001111101001 +010010110010 +101110010011 +011000101001 +111000111001 +110010011011 +110011010100 +100010110110 +110000011011 +111100100100 +101001111011 +110100010011 +101110100100 +000011111000 +001110101011 +101000001111 +111100000100 +010110001110 +010111011010 +100100101011 +110010111111 +011001011011 +000101100001 +010011001001 +000111111010 +000000011111 +011011000011 +111011110001 +110110010101 +111100010000 +011101100001 +001110000010 +110101011010 +000101011100 +011110000011 +100010010011 +011100100000 +001111111101 +000101000111 +001001011010 +101111111001 +110000111011 +000001100001 +101000100111 +111111101100 +110001100111 +101110010110 +100110000111 +000110000010 +100001110100 +101111011011 +110110000010 +111000001101 +110100010010 +100011010011 +110000111110 +110100000000 +101110000001 +001001011111 +101000000101 +000100110111 +111010000101 +010111100101 +010011100011 +100110100001 +110101011101 +100011000101 +001001111101 +100111000110 +001001110101 +111110010110 +011000000111 +010011101110 +111010011000 +001101100010 +111101100101 +101011100000 +101100100011 +100010101101 +010000101101 +111000000010 +000010001010 +000110101110 +000110110001 +111110111101 +001111110100 +101101110011 +011110011011 +100010110111 +001110000101 +101010001000 +110000110101 +000110000011 +101101111001 +101100001011 +010000001101 +101110110010 +101001111001 +000100110100 +111100001000 +101010100010 +010100011111 +011110001101 +001100100001 +110100011101 +000001001101 +000001001111 +110000010000 +110010111011 +100001111100 +110100000010 +010111100100 +111011001110 +100101000100 +111011010010 +011101000011 +011100010100 +010101000010 +010110100001 +010011001100 +011100100100 +100000111010 +011001000111 +011101011101 +100010101001 +011001111110 +011101110001 +001110100010 +011100010110 +100111110001 +000101001100 +001101110001 +110101110000 +000110011001 +100000111000 +111101010001 +000001110001 +110111001000 +110110110111 +110111101100 +001110010110 +100001111101 +110101101111 +000110010101 +100010001010 +001110110000 +111000110100 +010101111100 +001000101010 +011010111101 +110001110111 +000010001000 +100100011100 +001000100110 +100000100110 +101001110100 +100111001011 +000011010010 +010111001010 +111000000011 +110110110000 +010110101010 +110011010110 +101101001010 +011110110001 +100011011101 +001110010011 +011100000100 +111100100101 +111011110010 +010110011101 +111101000100 +000110111011 +000001011000 +101111110000 +101000100110 +100100100000 +001010001110 +000111011110 +101000100100 +011111110111 +111100011001 +101010010001 +101100011101 +011000011000 +011111100100 +001100101000 +110001100001 +000010010111 +110100001111 +010010011001 +010100100100 +110110101111 +001010110000 +110011010111 +000010010101 +100111001110 +001100101011 +001111111100 +010111111100 +101101000010 +000001001110 +011111111110 +001010000111 +111011010110 +110110100011 +010001101000 +010011010111 +000100001010 +010000100010 +000111100100 +011000010011 +001011000001 +001101001111 +100111010111 +100010100001 +010000110110 +111010101011 +010111011100 +011111011010 +001110100101 +010100110010 +100001000010 +011111110011 +100011011010 +110100011100 +011101111011 +101011011100 +111110001011 +101011010010 +111010101101 +011110010111 +011101100111 +000110100010 +110011100110 +100000010101 +111111100111 +101000110101 +110011001101 +100010011111 +111000011011 +101010000000 +111100110010 +001000011101 +001001100110 +101011001011 +010011111010 +110000110100 +100010000000 +100111111111 +101011100010 +011000100100 +111101010100 +100011111101 +010001110100 +100100101110 +111111000000 +001101111101 +011100101011 +111011110111 +001001101101 +110110000100 +101100111110 +000000001100 +110100011010 +001011010010 +111000110101 +011111100001 +000000101110 +110000010111 +100011111011 +111111000101 +110011101110 +000011000111 +001011101100 +100000000000 +011001010011 +111001010010 +000110101111 +111111111000 +000101110100 +111000010000 +100011011100 +111001111000 +101001011010 +011101111000 +111111110101 +100110101110 +100100010001 +100000101100 +001000001101 +000010110010 +110001000011 +111111011011 +010100010111 +101010001001 +000111011011 +001011111101 +110111110011 +011001100010 +011101111010 +001000000001 +101001100100 +110101110100 +111110011111 +111011111011 +111011111010 +101010000001 +001011010110 +111001011111 +100011110001 +011100101101 +010010010100 +001001100010 +110110000110 +011111011011 +001100100110 +011110111010 +010101011101 +110101100011 +001101110110 +011110101111 +001101110101 +001100001111 +100101111110 +101111001011 +001000110000 +001110000001 +100110101111 +111001000011 +101101111000 +000010000101 +010011001101 +111110000001 +001111101011 +111010001100 +101001101001 +001011101010 +101001100101 +011100001001 +000100011111 +101101001101 +111110111011 +000100011101 +100101101000 +101110011011 +001111100010 +101110011110 +110001000100 +110101010100 +011101000101 +011110001010 +110100011000 +001000100100 +111000011100 +000111110101 +011010101011 +000011110111 +100111110100 +100110100101 +011100100110 +000111111001 +010001110010 +001110111001 +010011111100 +100111011010 +001001000110 +111010010100 +110101000011 +100001111111 +111001001011 +001100100101 +110001001111 +011011010010 +110110000000 +010101111110 +011011010000 +110100101010 +100001100001 +010100110011 +101000011101 +111100000111 +010100111010 +101000001001 +101110010000 +010100010010 +100110011110 +010011111101 +011011000000 +101011100100 +101100110100 +111001101110 +001101101111 +101000010011 +000101001111 +001011101001 +001011111000 +001001010000 +111110101001 +110101100001 +011100001010 +100111010100 +010001001111 +001110100011 +100101111100 +010101011110 +000110111010 +111010101110 +001110001110 +011101001000 +010001000000 +011100110101 +111111001100 +011110101011 +010111011000 +100100111111 +110111111000 +001010100101 +001110011001 +010101001001 +101111101010 +011110001110 +100001000110 +110100001010 +000011001011 +101011000111 +000010001001 +011010100000 +011101011100 +110100000111 +101000111000 +011100011110 +111101110001 +001010010100 +011111110101 +111101000000 +111000010111 +001111010100 +000110000000 +001100010010 +010000111000 +111101101000 +101001011001 +010011100100 +111101111000 +101110001010 +101101110111 +010011000111 +100000011100 +100001100010 +100011011111 +010110001010 +100011111100 +110110011100 +011111101101 +111111101000 +100101110000 +100010100011 +100000010000 +100000100010 +001111011110 +000101111101 +111111111111 +111101100110 +010111110110 +101111100101 +000010110111 +010000011000 +000010111000 +010011111001 +010011001010 +101011101000 +001010111000 +010000110100 +100011011011 +100100000010 +001011000011 +001110011111 +010000110010 +010110110110 +110100110110 +000010101011 +010101000101 +001011010011 +100011001101 +001100000110 +101010100101 +111110011000 +101110111111 +111011101010 +010000010011 +101101110010 +010110110101 +000011111111 +111111001010 +000101000011 +000100000110 +111101110011 +000010101010 +100111011110 +101110001001 +100000000111 +111000011001 +101101101111 +101110010111 +111010011001 +011010110001 +010011101100 +110110010011 +010000001011 +001010100001 +110111011101 +111110111000 +110110101010 +100011000111 +101010111010 +101101111110 +100110101101 +101111101101 +111101100000 +010110000101 +101010001101 +011110101010 +000100001011 +001001011001 +000011000101 +011110000010 +111110001010 +111101010111 +011111000000 +010000000011 +101010100001 +011101101110 +110111110000 +111111101001 +100101111101 +011011011001 +101101000110 +000101101000 +110001011111 +011100010011 +111111111101 +001010000100 +111010001001 +101110110011 +111001010001 +110011100100 +000101100111 +011000001000 +011010101111 +000101000010 +111001000110 +101101100001 +101100010010 +101000010000 +001001111000 +001100101100 +100101010010 +101000010110 +111001100100 +111001110010 +100000010100 +011011111111 +100100001101 +011010100110 +101010010101 +011101110111 +110101011111 +010101010110 +011010000011 +000010000100 +011001100100 +101011011111 +110000100111 +001011001001 +000000101001 +011000111010 +100110001001 +111011100101 +000100101111 +100001001001 +101110000000 +100001001110 +111101100111 +111011111100 +000011011001 +000000100001 diff --git a/day3/day3Part1 b/day3/day3Part1 new file mode 100755 index 0000000..25abbdb Binary files /dev/null and b/day3/day3Part1 differ diff --git a/day3/day3Part1.cpp b/day3/day3Part1.cpp new file mode 100644 index 0000000..5991e17 --- /dev/null +++ b/day3/day3Part1.cpp @@ -0,0 +1,55 @@ +#include +#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; + epsilonRateBin[i] = 0; + } + else + { + gammaRateBin[i] = 0; + epsilonRateBin[i] = 1; + } + } + cout << "Gamma Rate (Binary): "; + for(int i=0;i<12;i++) cout << gammaRateBin[i]; + + cout << "\tEpsilon Rate (Binary): "; + for(int i=0;i<12;i++) cout << epsilonRateBin[i]; + + for(int i=0;i<12;i++) + { + gammaRateDec += gammaRateBin[i] * pow(2,11-i); + epsilonRateDec += epsilonRateBin[i] * pow(2,11-i); + } + cout << "\t Gamma Rate (Decimal): " << gammaRateDec << "\tEpsilon Rate (Decimal): " << epsilonRateDec; + powerConsumption = gammaRateDec * epsilonRateDec; + cout << "Power Consumption: " << powerConsumption; + return 0; +} diff --git a/day3/day3Part2.cpp b/day3/day3Part2.cpp new file mode 100644 index 0000000..e69de29