Guest User

bad dailyprog solution

a guest
Oct 21st, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. My solution is somewhat trivial, but with some thought and intuition behind it. Just a theory, not a very good one - no mathematical proofs.
  2.  
  3. 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.
  4.  
  5. They are:
  6.  
  7. 23
  8.  
  9. 14
  10.  
  11. ------------
  12.  
  13. 24
  14.  
  15. 13
  16.  
  17. -----------
  18.  
  19. 32
  20.  
  21. 14
  22.  
  23. 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:
  24.  
  25. 424
  26.  
  27. 313
  28.  
  29. 424
  30.  
  31.  
  32.  
  33. 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
  34.  
  35. 4242424.....(2 if n is even, 4 if odd)
  36.  
  37. 3131313....(1 if n is even, 3 if odd)
  38.  
  39. ............
  40.  
  41. (3,1 row if m is even, 4,2 row if odd)
  42.  
  43. As such my current solution is:
  44.  
  45. def grid(n, m=None):
  46. m = n if m is None else m
  47. pattern = [[4,2], [3,1]]
  48. board = []
  49. board_sum = 0
  50. for y in range(n):
  51. row = []
  52. for x in range(m):
  53. row.append(pattern[y%2][x%2])
  54. board.append(row)
  55. board_sum += sum(row)
  56. return board_sum, board
  57.  
  58. For which the square n x n sums are as follows:
  59.  
  60. n | sum
  61. -------|---------
  62. 2 | 10
  63. 3 | 27
  64. 4 | 40
  65. 5 | 70
  66. 6 | 90
  67. 7 | 133
  68. 8 | 160
  69. 9 | 216
  70.  
  71. I gladly await being proven wrong =)
Add Comment
Please, Sign In to add comment