# [Community Puzzle] Merlin's Magic Square

Coding Games and Programming Challenges to Code Better

Created by @Lisa-Has-Ideas,validated by @Konstant,@Remi and @Rafarafa.
If you have any issues, feel free to ping them.

I know I must have solved it some time ago.
Thatās it - Coding Games and Programming Challenges to Code Better

Very similar, yet not the same. Here I could invoke the great wizard āXorā. In the other puzzle the grid size could be too large for this approach.

1 Like

And also (as I understand it), each button in that āVery Hardā puzzle all have the same effect.
In This puzzle here, there are 3 different effects based on the location of the button on the square.

The real difference is that you have to find only one button in this puzzle, whereas you a to find a real solution in the other, and with a variable size. That makes the difficulty āvery hardā.

3 Likes

Merlin Magic square solution is a easy one or difficult.

That has to be a record for number of Test cases.

1 Like

Iām a bit confused, maybe Iām just missing something obvious?

If the initial sequence is

``````~ * ~
~ ~ ~
~ * ~
``````

And you do a transformation by pushing 8 (the bottom row will transform)

``````~ * ~
~ ~ ~
* ~ *
``````

If you push 8 again (it will reverse what it just did)

``````~ * ~
~ ~ ~
~ * ~
``````

Then 4 (it will reverse the left most column)

``````* * ~
* ~ ~
* * ~
``````

Then 6 (it will reverse the right most column)

``````* * *
* ~ *
* * *
``````

Which does get the correct result, as the first test case is 8 8 4 6 ( with 6 being the answer ).

*** Edited for correctness as per @cedricdd

1 Like

Hi,

When you push 4, the affected ones are 1,4,7 but in your example you are changing 1,4,7,8 & 9.

2 Likes

Why is the 4th, and 5th solution is ***, ***, *** ???

I mean, the solution should be ***, ~, ***ā¦

Hi Life ā
Iām not sure what you mean. Can you ask it a different way?

Hi everyone,
iām trying to solve this in python. Iām quite new to programing, and i have difficulties to find a way for solving this puzzle. For now, all i have done is :

• changing everything in lists (rows and inputs)
• replacing elements of row when pressing 8 or 2
My process seems a bit off, and very very long, so do you have a hint for me?

Hi Halarikā
thanks for posting, and thanks for playing my puzzle.

Youāre going through a learning process for sure so āstruggling thru itā is good for you.

I would suggest you write in pseudocode first.
In other words, write out in plain simple English what you want the computer to do.
Then if you canāt figure out how to translate some of that into python just Google it with the word python at the end like ācheck if two lists match exactly pythonā

I also provided in the puzzle two links that will show you someone playing it or let you play it yourself in case that is helpful to inspire the pseudocode.

iāll try this

1 Like

Hi there,
Iām trying to solve this puzzle in C++ but I wonder if there is an issue on it ?
Some of tests cases work (also some āhardā one) but some donāt. Really strange.
Let me show the inputs for Test case 2. For convenience, my program uses ā1ā for lit and ā0ā for non lit.

Each time a key is pressed, the program shows the input, the key pressed, and the output.

``````Initial input:
~ ~ *
* * ~
* * ~
Apply Lizzo pressed buttons
0 0 1
1 1 0
1 1 0
Key pressed : 4
1 0 1
0 1 0
0 1 0

1 0 1
0 1 0
0 1 0
Key pressed : 5
1 0 1
0 0 0
0 1 0
``````

The test case said : Expected 8 .
This seems really strange. No single key can solve this puzzle in that state
Did I omit something ?

Hi,

When you press the button 5 it will reverse the position 2, 4, 5, 6 & 8

1 Like

I missed that ! It was not so explicit for me. I read āreverse the button 5ā .
For the others cases, the text enumerated all the buttons that are invertedā¦ but not for the button ā5ā ā¦ :fear:

Many thanks @cedricdd

Hello, I am sure my problem has a absolutely obvious answer, but I seem to be overlooking it. I am coding in javascript btw. Here is some pseudocode:

``````MMS = MagicSquareSolver(StartSquare, All the buttons Lizzo presses)

for (let k go from 1 to 9){
Test = MagicSquareSolver(MMS, k)
if (Test == perfect){
}
}
function MagicSquareSolver (Square, arr){
alltheButtons=getalltheButtonsNeededtobepressed(arr);
for (let i 0 to alltheButtons.length){
if (Square[alltheButtons[i]=="*"){
Square[alltheButtons[i]="~";
} else{
Square[alltheButtons[i]="*";
}
return Square;
}
``````

The Problem I have is that When going through the test process, the MMS array (which should always be the one that lizzo did) changes with the Tests I do, so when I test if 5 is the correct button, it tries it as if lizzo pressed all the buttons she did + 1 to 4. I donĀ“t know if this was clear, please let me know if it wasnĀ“t.

Hope someone can help!

You can compile/run it without error? ā when there is no closing square-bracket?