Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- table = [
- [1, 2, 3, 4, 3],
- [2, 4, 3, 7, 5],
- [4, 3, 3, 3, 2],
- [7, 4, 0, 4, 2],
- [1, 5, 3, 0, 9]
- ]
- d = [(1, 0), (0, 1), (1, 1), (-1, 0), (0, -1), (-1, -1), (1, -1), (-1, 1), (0, 0)]
- def check(x, y, lx, ly):
- return x < 0 or y < 0 or x >= lx or x >= ly
- def f(s, x, y, lx, ly):
- maxp = (x, y)
- maxn = table[x][y] * s
- for dx, dy in d:
- cur = 0
- if check(x + s * dx, y * s * dy, lx, ly):
- continue
- for k in range(1, s + 1):
- cur += table[x + k * dx][y + k * dy]
- if maxn < cur:
- maxn = cur
- maxp = (x + s * dx, y * s * dy)
- return (maxn, maxp)
- print(f(2, 2, 2, 5, 5))
Advertisement
Add Comment
Please, Sign In to add comment