Solving all 42 versions of the Harry Potter potion puzzle

At the end of the book "Harry Potter and the Philosopher's Stone" there is an interesting riddle. Harry and Hermione enter the room, after which the entrances to it are blocked by magical fire, and they can only leave it by solving the following riddle:

In front of you is danger, and behind you is salvation,
Two will help you, whom you will find among us;
With one of the seven forward you will continue to move
The other one will carry you back immediately.
In two of us you will find only nettle wine,
And three bring death, stand in a row secretly.
So choose which one you are destined to taste,
To do this, we give four tips.
In vain did the poison try to hide its deadly heat,
You will always find it to the left of the wine,
And know that those who are at the edges hold a different gift,
But if you want to go further, none will help.
We differ in size everything, from edge to edge,
Your death does not sit in a smaller one, but not in a larger one either;
Second from the right end and second from the left
They taste like twins, even though they look different.

[from the "folk translation" of the book "Harry Potter and the Philosopher's Stone"]

Solving all 42 versions of the Harry Potter potion puzzle

Simply put, they need to figure out which bottles contain which potions.

In this article, we will solve all 42 possible variants of this puzzle using programming and draw a graph of the results (like the picture above, only much larger).

Wait a second, where did 42 options come from?

This is because the locations of the "smaller" and "larger" potions are not indicated. The larger one can be in one of seven places, which gives 6 remaining options for the smaller one, for a total of 7 * 6 \u42d 42. It will not be possible to find out exactly which arrangement JK Rowling had in mind when coming up with this riddle, unless she tells about it in your twitter. In the meantime, until that inevitable day comes, we can choose a random version and work with it. However, there will be no guarantees of its solvability, which is why we are working for the common good, solving all XNUMX variants of the puzzle (or proving their unsolvability).

YES DECIDE ALREADY

First, here are all the restrictions of the puzzle, reformulated in a simple way:

  1. There are two harmless potions, 3 poisoned ones, one that allows you to go forward, and one that allows you to go back.
  2. To the left of each of the two harmless potions is a poisonous one.
  3. The potions on both sides are different, and neither of them allows you to go forward.
  4. The largest and smallest bottles do not contain poison.
  5. The second bottle on the left and the second bottle on the right contain the same potion.

How to deal with it? Consider the following option. Note that, as the riddle says, in the row there is 1 bottle smaller than all the others in size, and 1 bottle larger than all the others.

Solving all 42 versions of the Harry Potter potion puzzle

Let's try to stupidly go through all the options - take one bottle at a time and select all possible options for the content.

For example, the first bottle cannot contain a potion that moves us forward due to restriction #3. Also, it does not contain a safe potion due to restriction #2 - poison cannot be placed to the left of it. This leaves us with the Poisoned Potion and the Returning Potion options. Let's try both options.

In the following images, green potions are poison, orange potions are safe drinks, blue potions are moving backwards, and purple potions are moving forward.

Solving all 42 versions of the Harry Potter potion puzzle

Solving all 42 versions of the Harry Potter potion puzzle

Let's repeat this process for both working options - take the second bottle and alternately try all the valid content options. This will give us the following:

Solving all 42 versions of the Harry Potter potion puzzle

Solving all 42 versions of the Harry Potter potion puzzle

Solving all 42 versions of the Harry Potter potion puzzle

Solving all 42 versions of the Harry Potter potion puzzle

Continuing in this vein, and discarding all working options in which some bottle cannot be filled with a potion without violating the listed restrictions, we will come to the only acceptable option:

Solving all 42 versions of the Harry Potter potion puzzle

Naturally, we had no guarantees to find a solution. There might not be a solution, or there might be more than one (and if you have multiple solutions, this is equivalent to the fact that the riddle cannot be solved, since it is not known which of the potions is correct).

Applying the algorithm to all variants gives us the following solutions. 8 puzzle options are solvable, 8 have no solutions, and 26 have multiple solutions.

Solving all 42 versions of the Harry Potter potion puzzle

More about solutions

Is there anything in common between all the solved variants of the puzzle? Yes! Please note that in them the smallest or largest bottles are in 2nd or 6th places. This allows us to conclude that the 2nd and 6th bottles contain safe potions due to restrictions #4 and #5. Without this step, we cannot eliminate the possibility that these bottles contain poison, and end up with several possible solutions. Also solved options require the second "special" bottle (smallest or largest) to be in 3rd or 4th place. Otherwise, the exact location of the potion that moves us forward cannot be found.

Results

I'll end with a quote from the book.

Hermione breathed out loudly, and Harry was surprised to see that she was smiling - it was the last thing he could think of. "Brilliant," said Hermione. “It’s not magic—it’s logic, a riddle. A lot of the greatest magicians don't have an ounce of logic and they'd be stuck here forever."

But hey, maybe we can figure out the canonical version of the puzzle based on the dialogue from the book:

“Understood,” she said. “The smallest bottle will take us through the black fire, and to the Stone.”

...

"Which one will let you return through the purple fire?"

Hermione pointed to a round bottle on the right side of the row.

Damn it. This option still gives us several solutions. Tweet, DR.

Code

If you are interested in the code for solving this puzzle and drawing diagrams, you can скачать здесь.

Source: habr.com

Add a comment