Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My solution is somewhat trivial, but with some thought and intuition behind it. Just a theory, not a very good one - no mathematical proofs.
- I started with a 2x2 matrix. There are 3 unique optimized solutions for a 2x2. When I say unique, I mean that there is no way to, through any combination of rotation, mirroring, or transposition, to turn one solution into another.
- They are:
- 23
- 14
- ------------
- 24
- 13
- -----------
- 32
- 14
- Now, expanding into a 3x3, I thought to start with one of the 3 2x2 solutions. In order to add a 5, it seemed to me like I would have to add so much scaffolding in order to fulfill the requirements that it would negate the potential gains of a 5, and be less efficient. /u/Godspiral has a couple of 3x3s which contain a 5, which are nearly maximized but ultimately fall short of the (theorized?) single unique solution:
- 424
- 313
- 424
-
- From n=2 to n=3 I saw one of the chiral solutions to n=2 patterned to create the solution to n=3. I theorize that this isn't a coincidence; that the n=2 solution, being the smallest chunk of a complete optimized square, when arranged properly and patterned, may result in the highest sum for any m by n grid. this follows the pattern
- 4242424.....(2 if n is even, 4 if odd)
- 3131313....(1 if n is even, 3 if odd)
- ............
- (3,1 row if m is even, 4,2 row if odd)
- As such my current solution is:
- def grid(n, m=None):
- m = n if m is None else m
- pattern = [[4,2], [3,1]]
- board = []
- board_sum = 0
- for y in range(n):
- row = []
- for x in range(m):
- row.append(pattern[y%2][x%2])
- board.append(row)
- board_sum += sum(row)
- return board_sum, board
- For which the square n x n sums are as follows:
- n | sum
- -------|---------
- 2 | 10
- 3 | 27
- 4 | 40
- 5 | 70
- 6 | 90
- 7 | 133
- 8 | 160
- 9 | 216
- I gladly await being proven wrong =)
Add Comment
Please, Sign In to add comment