advent-of-code/2018/day-11/01.py

30 lines
657 B
Python
Raw Normal View History

2018-12-11 10:47:24 +01:00
serial = 5535
cache = dict()
def get_power_level(x, y):
if (x, y) in cache:
return cache.get((x, y))
rack_id = x + 10
power_level = rack_id * y
power_level += serial
power_level *= rack_id
power_level = (power_level // 100) % 10
power_level -= 5
cache[(x, y)] = power_level
return power_level
m = dict()
for x in range(1, 299):
for y in range(1, 299):
level = 0
for i in [-1, 0, 1]:
for j in [-1, 0, 1]:
level += get_power_level(x + i, y + j)
m[x, y] = level
high_center = max(m, key=m.get)
print(f'{high_center[0] - 1},{high_center[1] - 1}')