part1 (1992B)
1--- Day 3: Binary Diagnostic --- 2 3The submarine has been making some odd creaking noises, so you ask it to produce a diagnostic report 4just in case. 5 6The diagnostic report (your puzzle input) consists of a list of binary numbers which, when decoded 7properly, can tell you many useful things about the conditions of the submarine. The first parameter 8to check is the [1m[37mpower consumption[0m. 9 10You need to use the binary numbers in the diagnostic report to generate two new binary numbers 11(called the [1m[37mgamma rate[0m and the [1m[37mepsilon rate[0m). The power consumption can 12then be found by multiplying the gamma rate by the epsilon rate. 13 14Each bit in the gamma rate can be determined by finding the [1m[37mmost common bit in the 15corresponding position[0m of all numbers in the diagnostic report. For example, given the following 16diagnostic report: 17 1800100 1911110 2010110 2110111 2210101 2301111 2400111 2511100 2610000 2711001 2800010 2901010 30 31Considering only the first bit of each number, there are five 0 bits and seven 1 bits. Since the 32most common bit is 1, the first bit of the gamma rate is 1. 33 34The most common second bit of the numbers in the diagnostic report is 0, so the second bit of the 35gamma rate is 0. 36 37The most common value of the third, fourth, and fifth bits are 1, 1, and 0, respectively, and so the 38final three bits of the gamma rate are 110. 39 40So, the gamma rate is the binary number 10110, or [1m[37m22[0m in decimal. 41 42The epsilon rate is calculated in a similar way; rather than use the most common bit, the least 43common bit from each position is used. So, the epsilon rate is 01001, or [1m[37m9[0m in decimal. 44Multiplying the gamma rate (22) by the epsilon rate (9) produces the power consumption, 45[1m[37m198[0m. 46 47Use the binary numbers in your diagnostic report to calculate the gamma rate and epsilon rate, then 48multiply them together. [1m[37mWhat is the power consumption of the submarine?[0m (Be sure to 49represent your answer in decimal, not binary.) 50 51