You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
657 B
Python

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}')