Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. from collections import defaultdict
  2. from math import inf
  3.  
  4. serial_number = 5535
  5.  
  6. def power(x, y):
  7. rack_id = x + 10
  8. res = y * rack_id
  9. res += serial_number
  10. res *= rack_id
  11. res //= 100
  12. res %= 10
  13. return res - 5
  14.  
  15. board=[[0]*300 for _ in range(300)]
  16. for y in range(300):
  17. for x in range(300):
  18. pw = power(x, y)
  19. board[y][x] = pw
  20.  
  21. squares = defaultdict(lambda:defaultdict(int)) #size : pos : sum
  22. mx = -inf
  23. for size in range(1, 300):
  24. for y in range(300 - size,-1,-1):
  25. for x in range(300 - size,-1,-1):
  26. strip = board[y][x]
  27. for shift in range(1,size):
  28. strip += board[y+shift][x]
  29. strip += board[y][x+shift]
  30. t = strip + squares[size - 1][x+1, y+1]
  31. squares[size][x, y] = t
  32. if t > mx:
  33. mx = t
  34. win = x,y,size
  35. print(win, t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement