-
Notifications
You must be signed in to change notification settings - Fork 0
/
day11.py
90 lines (74 loc) · 1.89 KB
/
day11.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import time
def createArr(x, y):
arr = []
for i in range(x):
arr2 = []
for j in range(y):
arr2.append(0)
arr.append(arr2)
return arr
def getPower(x, y, serial):
power = x * x * y + 20 * x * y + (x + 10) * serial + 100 * y
power //= 100
power %= 10
power -= 5
return power
def power_sum(grid, x, y, z = 3):
return sum(grid[x1][y1] for x1 in range(x, x + z) for y1 in range(y, y+z))
def main():
with open("input/input11.txt") as f:
data = f.read()
lines = f.readlines()
serial = int(data)
serial = 3999
arr = createArr(300, 300)
# print(getPower(101, 153, 71))
for x in range(300):
for y in range(300):
power = getPower(x + 1, y + 1, serial)
arr[x][y] = power
bestSum = 0
bestX = 0
bestY = 0
bestSize = 0
history = 0
oldX = 0
oldY = 0
done = False
for x in range(297):
for y in range(297):
sum = power_sum(arr, x, y)
if sum > bestSum:
history = 0
bestSum = sum
bestX = x + 1
bestY = y + 1
print(bestX, bestY)
bestSum = 0
bestX = 0
bestY = 0
bestSize = 0
history = 0
oldX = 0
oldY = 0
done = False
for z in range(10, 200):
if done == True:
break
startTime = time.time()
for x in range(300 - z):
for y in range(300 - z):
sum = power_sum(arr, x, y, z)
if sum > bestSum:
history = 0
bestSum = sum
bestX = x + 1
bestY = y + 1
bestSize = z
history+=1
if history > 200000:
done = True
break
print(bestX, bestY, bestSize)
if __name__ == "__main__":
main()