diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-04-07 17:18:18 -0400 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-04-07 17:19:39 -0400 |
| commit | 87ab487d59fa85dbe2afa55cc841b02805ae42ca (patch) | |
| tree | cd90ab715e1b5b5803674045dbafd6d51d27ac90 /src/11 | |
| parent | 1bcc82c5bfbde87edd03c01ffdf9ee5934681592 (diff) | |
| download | aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.tar.gz aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.zip | |
Reorder days into src
Diffstat (limited to 'src/11')
| -rw-r--r-- | src/11/input | 1 | ||||
| -rw-r--r-- | src/11/part1 | 88 | ||||
| -rw-r--r-- | src/11/part2 | 14 | ||||
| -rw-r--r-- | src/11/solve.py | 76 |
4 files changed, 179 insertions, 0 deletions
diff --git a/src/11/input b/src/11/input new file mode 100644 index 0000000..141d29f --- /dev/null +++ b/src/11/input @@ -0,0 +1 @@ +1955 diff --git a/src/11/part1 b/src/11/part1 new file mode 100644 index 0000000..a14a37f --- /dev/null +++ b/src/11/part1 @@ -0,0 +1,88 @@ +--- Day 11: Chronal Charge --- + +You watch the Elves and their sleigh fade into the distance as they head toward the North Pole. + +Actually, you're the one fading. The falling sensation returns. + +The low fuel warning light is illuminated on your wrist-mounted device. Tapping it once causes it to +project a hologram of the situation: a [1m[97m300x300[0m grid of fuel cells and their current power levels, +some negative. You're not sure what negative power means in the context of time travel, but it can't +be good. + +Each fuel cell has a coordinate ranging [1m[97mfrom 1 to 300[0m in both the X (horizontal) and Y (vertical) +direction. In X,Y notation, the top-left cell is 1,1, and the top-right cell is 300,1. + +The interface lets you select [1m[97many 3x3 square[0m of fuel cells. To increase your chances of getting to +your destination, you decide to choose the 3x3 square with the [1m[97mlargest total power[0m. + +The power level in a given fuel cell can be found through the following process: + + + - Find the fuel cell's [1m[97mrack ID[0m, which is its [1m[97mX coordinate plus 10[0m. + + - Begin with a power level of the [1m[97mrack ID[0m times the [1m[97mY coordinate[0m. + + - Increase the power level by the value of the [1m[97mgrid serial number[0m (your puzzle input). + + - Set the power level to itself multiplied by the [1m[97mrack ID[0m. + + - Keep only the [1m[97mhundreds digit[0m of the power level (so 12[1m[97m3[0m45 becomes 3; numbers with no hundreds +digit become 0). + + - [1m[97mSubtract 5[0m from the power level. + + +For example, to find the power level of the fuel cell at 3,5 in a grid with serial number 8: + + + - The rack ID is 3 + 10 = [1m[97m13[0m. + + - The power level starts at 13 * 5 = [1m[97m65[0m. + + - Adding the serial number produces 65 + 8 = [1m[97m73[0m. + + - Multiplying by the rack ID produces 73 * 13 = [1m[97m949[0m. + + - The hundreds digit of [1m[97m9[0m49 is [1m[97m9[0m. + + - Subtracting 5 produces 9 - 5 = [1m[97m4[0m. + + +So, the power level of this fuel cell is [1m[97m4[0m. + +Here are some more example power levels: + + + - Fuel cell at 122,79, grid serial number 57: power level -5. + + - Fuel cell at 217,196, grid serial number 39: power level 0. + + - Fuel cell at 101,153, grid serial number 71: power level 4. + + +Your goal is to find the 3x3 square which has the largest total power. The square must be entirely +within the 300x300 grid. Identify this square using the X,Y coordinate of its [1m[97mtop-left fuel +cell[0m. For example: + +For grid serial number 18, the largest total 3x3 square has a top-left corner of [1m[97m33,45[0m (with a total +power of 29); these fuel cells appear in the middle of this 5x5 region: + +-2 -4 4 4 4 +-4 [1m[97m 4 4 4 [0m-5 + 4 [1m[97m 3 3 4 [0m-4 + 1 [1m[97m 1 2 4 [0m-3 +-1 0 2 -5 -2 + +For grid serial number 42, the largest 3x3 square's top-left is [1m[97m21,61[0m (with a total power of 30); +they are in the middle of this region: + +-3 4 2 2 2 +-4 [1m[97m 4 3 3 [0m 4 +-5 [1m[97m 3 3 4 [0m-4 + 4 [1m[97m 3 3 4 [0m-3 + 3 3 3 -5 -1 + +[1m[97mWhat is the X,Y coordinate of the top-left fuel cell of the 3x3 square with the largest total +power?[0m + + diff --git a/src/11/part2 b/src/11/part2 new file mode 100644 index 0000000..8be7709 --- /dev/null +++ b/src/11/part2 @@ -0,0 +1,14 @@ +--- Part Two --- + +You're not sure what it's trying to paint, but it's definitely not a [1m[97mregistration identifier[0m. The +Space Police are getting impatient. + +Checking your external ship cameras again, you notice a white panel marked "emergency hull painting +robot starting panel". The rest of the panels are [1m[97mstill black[0m, but it looks like the robot was +expecting to [1m[97mstart on a white panel[0m, not a black one. + +Based on the Space Law Space Brochure that the Space Police attached to one of your windows, a valid +registration identifier is always [1m[97meight capital letters[0m. After starting the robot on a single +[1m[97mwhite panel[0m instead, [1m[97mwhat registration identifier does it paint[0m on your hull? + + diff --git a/src/11/solve.py b/src/11/solve.py new file mode 100644 index 0000000..66fc956 --- /dev/null +++ b/src/11/solve.py @@ -0,0 +1,76 @@ +import sys
+sys.path.append("../common")
+import aoc
+
+gridserial = int(aoc.data)
+
+# rack ID = x + 10
+# intial power = rackID * y
+# power += gridserial
+# power *= rackID
+# power = str(power)[2]
+# power -= 5
+
+def get_power(x,y):
+ id = x + 10
+ power = id * y
+ power += gridserial
+ power *= id
+ spower = str(power)
+ if len(spower) > 2:
+ power = int(spower[-3])
+ else:
+ power = 0
+ power -= 5
+ return power
+
+def solve1(args):
+ maxpower = None
+ coords = None
+ for x in range(300-2):
+ for y in range(300-2):
+ power = 0;
+ for i in range(3):
+ for j in range(3):
+ power += get_power(x+i,y+j)
+ if maxpower == None or power > maxpower:
+ maxpower = power
+ coords = (x, y)
+
+ return f"{coords[0]},{coords[1]}"
+
+def gen_map():
+ vmap = [[0 for y in range(300)] for x in range(300)]
+ for x in range(300):
+ for y in range(300):
+ vmap[x][y] = get_power(x,y)
+ return vmap
+
+def solve2(args):
+ maxpower = None
+ res = None
+ pmap = gen_map()
+ vmap = [[list() for y in range(300)] for x in range(300)]
+ for s in range(1, 301):
+ aoc.debug(f"\rTrying: {s}", end="")
+ cmaxpower = None
+ cres = None
+ for x in range(300-(s-1)):
+ for y in range(300-(s-1)):
+ vmap[x][y] += [pmap[x+(s-1)][y+i] for i in range(s)]
+ vmap[x][y] += [pmap[x+i][y+(s-1)] for i in range(s-1)]
+ power = sum(vmap[x][y]);
+ if cmaxpower == None or power > cmaxpower:
+ cmaxpower = power
+ cres = (x, y, s)
+ if maxpower == None or cmaxpower > maxpower:
+ maxpower = cmaxpower
+ res = cres
+ elif cmaxpower < maxpower:
+ break
+
+ aoc.debug("\r" + " " * 50 + "\r", end="")
+
+ return f"{res[0]},{res[1]},{res[2]}"
+
+aoc.run(solve1, solve2, sols=["21,93", "231,108,14"])
|
