We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
For those, who, like me, struggle to understand the algorithm even after googling one. It took me time, imagination and a couple of colored pens, but I figured out the pattern. Look at this image.
The pattern is that concrete elements can only be 'flipped' to certain positions. Looking at coordinates, you can always say what other elements can be placed instead of this exact element.
This pattern works for every positive n because it's basically about rotating a square array and getting "upside-down", "right-to-left" and "reversed diagonal" views. I suggest you take a sheet of paper and imagine how the similar matrix of letters 3x3 can be flipped in each of 3 directions. This schema can then be applied to the initial 6x6 matrix.
I didn't even understand the question until I saw your artwork, actually I still don't know the question, but now I know the answer... as indian jones said... it belongs in the louver!
Yes, I was actually struggling to understand, until i did some console.log() in an existing solution and came back to this diagram. Then it all make sense. Thanks for this.
Im guess people will keep thanking you in 100years to come,LOL
Before seeing the image I actually forgot that with little effort you can get any point anywhere without disturbing the other points like rubix cube. So just check the currosponding points
I came up with this solution based on your explanation.
def flippingMatrix(matrix):
l = len(matrix)-1
num_groups = (len(matrix)**2)/4
iterator = int(num_groups**(1/2))
groups = []
for i in range(iterator):
for j in range(iterator):
groups.append([matrix[i][j], matrix[i][l-j], matrix[l-i][j], matrix[l-i][l-j]])
maxs = []
for i in range(len(groups)):
maxs.append(max(groups[i]))
return sum(maxs)
Thank you so much for your help. I literally understood the problem immediatly just by looking the image, and reading the general rule made it more easier.
but when you find max value for a certain position and flip the necesary row/col this may alter another already sorted col/row... so its more complex to just find max values and add it to total.
Look at this example:
original matrix:
[112 42 83 119 ]
[56 125 56 49 ]
[15 78 101 43 ]
[62 98 114 108 ]
max A: 119
reversed row: 0
[119 83 42 112 ]
[56 125 56 49 ]
[15 78 101 43 ]
[62 98 114 108 ]
max B: 114
reversed row: 3
reversed col: 1
[119 114 42 112 ]
[56 78 56 49 ]
[15 125 101 43 ]
[108 83 98 62 ]
max C: 56
Not necesary flip
[119 114 42 112 ]
[56 78 56 49 ]
[15 125 101 43 ]
[108 83 98 62 ]
max D: 125
reversed col: 1 <<<--- HERE
[119 83 42 112 ]
[56 125 56 49 ]
[15 78 101 43 ]
[108 114 98 62 ]
--final matrix--
[119 83 42 112 ]
[56 125 56 49 ]
[15 78 101 43 ]
As you can see, when i reversed column 1 to get value 125 on D, it alter B =114
ee, when i reversed column 1 to get value 125 on D, it alter B =114
I think the designer of the problem, should answer this observation. Please do not say to solve it with below solution, since we all know this solution works. However, this solution, was not described the way the original question is described.
Thanks
sum_arr = []
for row in range(n):
for col in range(n):
max_of = max([matrix[row][col],matrix[row][2*n-1-col],matrix[2*n-1-row][col],matrix[2*n-1-row][2*n-1-col]])
print("Comparing max among these elements:")
print([matrix[row][col],matrix[row][2*n-1-col],matrix[2*n-1-row][col],matrix[2*n-1-row][2*n-1-col]])
sum_arr.append(max_of)
print(row, col, max_of, sum_arr)
return sum(sum_arr)
Hi Hello_io,
thanks for the explanation. much appreciated.
My confusion is that, if we keep reversing entire rows and columns, do we ever end up at the best possible highest sum ever? thanks.!
Flipping the Matrix
You are viewing a single comment's thread. Return to all comments →
For those, who, like me, struggle to understand the algorithm even after googling one. It took me time, imagination and a couple of colored pens, but I figured out the pattern. Look at this image.
https://drive.google.com/uc?export=view&id=1t_7fU2LD06qfyIOiFTJ51X8npx0qmcca
The pattern is that concrete elements can only be 'flipped' to certain positions. Looking at coordinates, you can always say what other elements can be placed instead of this exact element.
So what you need to do is:
And sum them up. Voila!
The general rule:
Oh my god. I looked at that image and I immediately understood the pattern. Thank you so much.
Thanks so much this was really helpful
Thanx for sharing, really helpful
Thank you so much, I couldn't figure out how to do it until I saw your pattern! I'd like to know how you came up with this solution!
will this pattern work for bigger number of n for example if n=3, the square matrix will be 6x6, how will you make this exact pattern now?
This pattern works for every positive n because it's basically about rotating a square array and getting "upside-down", "right-to-left" and "reversed diagonal" views. I suggest you take a sheet of paper and imagine how the similar matrix of letters 3x3 can be flipped in each of 3 directions. This schema can then be applied to the initial 6x6 matrix.
Yes! This finally helped me get to a solution! Thank you!
Very verbose, to facilitate understanding and debugging:
This is Brilliant!
Thanks for sharing! The image really helped me to understand the solution.
Thanks to you, I got a lot of help. 감사합니다~
that diagram helped SO much, thank you for sharing!!
You are amazing!!! Russian people are the math masters!
This is awesome, the picture kill it. Thanks so much! Just wish one day I will be able to craft brilliant solutions like this!
great image, thanks.
Thats a pretty good clarification
Love the visual and your pseudocode... very helpful!
But what if you have a 50x50 matrix ? sure you still have 1 of 4 corners, but then you have to find the max 25x25 top left corner combination.
I don't get it this challenge is so crazy....
Thank you for sharing! this is really helpful on improving my algorithm for this challenge
I didn't even understand the question until I saw your artwork, actually I still don't know the question, but now I know the answer... as indian jones said... it belongs in the louver!
OMG thank you so much for this. It gave me some clues, even though I still do not know how to solve it. I am struggling with this exercise A LOT!
Pictures are worth a thousand words. Thanks much for posting this!
That was really a very good explanation. Thank you so much
Thank you so much for clarify the question! I really didn't get what was the actually problem but with your image it became very very understandable.
Yes, I was actually struggling to understand, until i did some console.log() in an existing solution and came back to this diagram. Then it all make sense. Thanks for this.
Im guess people will keep thanking you in 100years to come,LOL
Before seeing the image I actually forgot that with little effort you can get any point anywhere without disturbing the other points like rubix cube. So just check the currosponding points
Thank you so much!
Thank you for sharing this. Image was worth a 1000 words.
Please help hell_io for i:=0;i
Thanks for the image..
This helped a lot, THANKS for sharing
Bless you, this was super helpful and made the problem easier to understand.
Thank you so much for the clarity.
I came up with this solution based on your explanation.
def flippingMatrix(matrix):
very helpful!
Nice job,
I apply your idea:
Hey you - that is just great!!!!!!!!!! I am so very prod of you. Thank you very much.
Thank you so much for your help. I literally understood the problem immediatly just by looking the image, and reading the general rule made it more easier.
but when you find max value for a certain position and flip the necesary row/col this may alter another already sorted col/row... so its more complex to just find max values and add it to total. Look at this example: original matrix:
[112 42 83 119 ]
[56 125 56 49 ]
[15 78 101 43 ]
[62 98 114 108 ]
max A: 119 reversed row: 0
[119 83 42 112 ]
[56 125 56 49 ]
[15 78 101 43 ]
[62 98 114 108 ]
max B: 114 reversed row: 3 reversed col: 1
[119 114 42 112 ]
[56 78 56 49 ]
[15 125 101 43 ]
[108 83 98 62 ]
max C: 56 Not necesary flip
[119 114 42 112 ]
[56 78 56 49 ]
[15 125 101 43 ]
[108 83 98 62 ]
max D: 125 reversed col: 1 <<<--- HERE
[119 83 42 112 ]
[56 125 56 49 ]
[15 78 101 43 ]
[108 114 98 62 ]
--final matrix--
[119 83 42 112 ]
[56 125 56 49 ]
[15 78 101 43 ]
As you can see, when i reversed column 1 to get value 125 on D, it alter B =114
ee, when i reversed column 1 to get value 125 on D, it alter B =114
I think the designer of the problem, should answer this observation. Please do not say to solve it with below solution, since we all know this solution works. However, this solution, was not described the way the original question is described.
Thanks
sum_arr = []
Thank you so much for your explanation
it is really helpful to visualize :)
Goodness. I was on the right track, just didnt connect the dots. Great explanation!
Thank you, this was really elegantly explained!
Thank you for the picture!
Thank you!!! This really made me understand the solution!!!
The image was really the key, ty!
Hi Hello_io, thanks for the explanation. much appreciated. My confusion is that, if we keep reversing entire rows and columns, do we ever end up at the best possible highest sum ever? thanks.!
Thank you. Really helpful explanation.