-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11-2.py
More file actions
executable file
·53 lines (43 loc) · 1.15 KB
/
11-2.py
File metadata and controls
executable file
·53 lines (43 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import re
import sys
serial = 7857
def calc(x, y):
rackid = x + 10
power = (rackid * y + serial) * rackid
power -= (power % 100)
power = int(power / 100)
power = power % 10
return power - 5
def key(x,y):
return str(x) + "," + str(y)
def caltot(x,y,s):
return sum(grid[key(xp,yp)] for xp in range(x, x+s) for yp in range(y, y+s) )
grid = {}
for x in range(1, 301):
for y in range(1, 301):
grid[key(x,y)] = calc(x,y)
powgrid = {}
mx = -9999999
# answer is in size 14
# this isn't a great solution (slow), but got lucky
for s in range(14, 300):
print(s, len(powgrid))
if len(powgrid) > 0:
maxkey = max(powgrid, key=lambda i:powgrid[i])
print(s, powgrid[maxkey])
print(s, maxkey)
sys.stdout.flush()
exit()
for x in range(1, 300 - s + 1):
#print('x', x)
for y in range(1, 300 - s + 1):
v = caltot(x,y,s)
if v > mx:
mx = v
else:
continue
powgrid[key(x,y) + "," + str(s)] = v
#print(powgrid)
maxkey = max(powgrid, key=lambda x:powgrid[x])
print(powgrid[maxkey])
print(maxkey)