My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add solution for 2018/11

+49
+46
2018/day11.py
··· 1 + import fileinput 2 + 3 + 4 + def power_level(x, y, serial): 5 + x += 1 6 + y += 1 7 + rack_id = x + 10 8 + return (((rack_id * y + serial) * rack_id // 100) % 10) - 5 9 + 10 + 11 + SERIAL = int(fileinput.input()[0]) 12 + SIZE = 300 13 + GRID = [[power_level(x, y, SERIAL) for x in range(SIZE)] for y in range(SIZE)] 14 + 15 + overall_sum = 0 16 + overall_x = 0 17 + overall_y = 0 18 + overall_size = 0 19 + 20 + for size in range(3, 16): # window size of 16 is good enough...right? 21 + best_sum = 0 22 + best_x = 0 23 + best_y = 0 24 + 25 + for y in range(SIZE - size): 26 + for x in range(SIZE - size): 27 + total = 0 28 + for j in range(size): 29 + for i in range(size): 30 + total += GRID[y + j][x + i] 31 + 32 + if total > best_sum: 33 + best_sum = total 34 + best_x = x 35 + best_y = y 36 + 37 + if size == 3: 38 + print "Coordinate of most powerful 3x3 grid: {},{}".format(best_x + 1, best_y + 1) 39 + 40 + if best_sum > overall_sum: 41 + overall_sum = best_sum 42 + overall_x = best_x 43 + overall_y = best_y 44 + overall_size = size 45 + 46 + print "Identifier of the largest total power: {},{},{}".format(overall_x + 1, overall_y + 1, overall_size)
+1
2018/inputs/11.txt
··· 1 + 3214
+2
2018/outputs/11.txt
··· 1 + 21,42 2 + 230,212,13