part1 (3257B)
1--- Day 11: Chronal Charge --- 2 3You watch the Elves and their sleigh fade into the distance as they head toward the North Pole. 4 5Actually, you're the one fading. The falling sensation returns. 6 7The low fuel warning light is illuminated on your wrist-mounted device. Tapping it once causes it to 8project a hologram of the situation: a [1m[97m300x300[0m grid of fuel cells and their current power levels, 9some negative. You're not sure what negative power means in the context of time travel, but it can't 10be good. 11 12Each fuel cell has a coordinate ranging [1m[97mfrom 1 to 300[0m in both the X (horizontal) and Y (vertical) 13direction. In X,Y notation, the top-left cell is 1,1, and the top-right cell is 300,1. 14 15The interface lets you select [1m[97many 3x3 square[0m of fuel cells. To increase your chances of getting to 16your destination, you decide to choose the 3x3 square with the [1m[97mlargest total power[0m. 17 18The power level in a given fuel cell can be found through the following process: 19 20 21 - Find the fuel cell's [1m[97mrack ID[0m, which is its [1m[97mX coordinate plus 10[0m. 22 23 - Begin with a power level of the [1m[97mrack ID[0m times the [1m[97mY coordinate[0m. 24 25 - Increase the power level by the value of the [1m[97mgrid serial number[0m (your puzzle input). 26 27 - Set the power level to itself multiplied by the [1m[97mrack ID[0m. 28 29 - Keep only the [1m[97mhundreds digit[0m of the power level (so 12[1m[97m3[0m45 becomes 3; numbers with no hundreds 30digit become 0). 31 32 - [1m[97mSubtract 5[0m from the power level. 33 34 35For example, to find the power level of the fuel cell at 3,5 in a grid with serial number 8: 36 37 38 - The rack ID is 3 + 10 = [1m[97m13[0m. 39 40 - The power level starts at 13 * 5 = [1m[97m65[0m. 41 42 - Adding the serial number produces 65 + 8 = [1m[97m73[0m. 43 44 - Multiplying by the rack ID produces 73 * 13 = [1m[97m949[0m. 45 46 - The hundreds digit of [1m[97m9[0m49 is [1m[97m9[0m. 47 48 - Subtracting 5 produces 9 - 5 = [1m[97m4[0m. 49 50 51So, the power level of this fuel cell is [1m[97m4[0m. 52 53Here are some more example power levels: 54 55 56 - Fuel cell at 122,79, grid serial number 57: power level -5. 57 58 - Fuel cell at 217,196, grid serial number 39: power level 0. 59 60 - Fuel cell at 101,153, grid serial number 71: power level 4. 61 62 63Your goal is to find the 3x3 square which has the largest total power. The square must be entirely 64within the 300x300 grid. Identify this square using the X,Y coordinate of its [1m[97mtop-left fuel 65cell[0m. For example: 66 67For grid serial number 18, the largest total 3x3 square has a top-left corner of [1m[97m33,45[0m (with a total 68power of 29); these fuel cells appear in the middle of this 5x5 region: 69 70-2 -4 4 4 4 71-4 [1m[97m 4 4 4 [0m-5 72 4 [1m[97m 3 3 4 [0m-4 73 1 [1m[97m 1 2 4 [0m-3 74-1 0 2 -5 -2 75 76For grid serial number 42, the largest 3x3 square's top-left is [1m[97m21,61[0m (with a total power of 30); 77they are in the middle of this region: 78 79-3 4 2 2 2 80-4 [1m[97m 4 3 3 [0m 4 81-5 [1m[97m 3 3 4 [0m-4 82 4 [1m[97m 3 3 4 [0m-3 83 3 3 3 -5 -1 84 85[1m[97mWhat is the X,Y coordinate of the top-left fuel cell of the 3x3 square with the largest total 86power?[0m 87 88