Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- from math import inf
- serial_number = 5535
- def power(x, y):
- rack_id = x + 10
- res = y * rack_id
- res += serial_number
- res *= rack_id
- res //= 100
- res %= 10
- return res - 5
- board=[[0]*300 for _ in range(300)]
- for y in range(300):
- for x in range(300):
- pw = power(x, y)
- board[y][x] = pw
- squares = defaultdict(lambda:defaultdict(int)) #size : pos : sum
- mx = -inf
- for size in range(1, 300):
- for y in range(300 - size,-1,-1):
- for x in range(300 - size,-1,-1):
- strip = board[y][x]
- for shift in range(1,size):
- strip += board[y+shift][x]
- strip += board[y][x+shift]
- t = strip + squares[size - 1][x+1, y+1]
- squares[size][x, y] = t
- if t > mx:
- mx = t
- win = x,y,size
- print(win, t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement