# Bartender's nightmare

Turn the "before" picture into the "after" picture by pouring the ice cubes from one glass to another.

# After

Specifically:

• Start: There are three glasses. The first glass is a 5-capacity glass with the word ENJOY written downward on 5 ice cubes. The second glass is a 5-capacity glass which is empty. The third glass is a 4-capacity glass with the word THIS written downward on 4 ice cubes.
• Objective: Pour ice cubes from one glass to another until the first glass is empty and the word ENJOY is written downward in the second glass. The third glass should end as it started, with the word THIS written downward.
• Movement: A pour continues until either the donor glass is empty or the recipient glass is full, whichever happens first.
• Note: Letter order is reversed (upside-down) after pouring. I.e., if ABCD is poured, it will appear as DCBA in the recipient glass.
• Do we have to worry about letter orientation too? (e.g. E vs ∃?) Also, is there actually any wordplay going on here?
– Deusovi
Oct 31, 2022 at 23:57
• Can't we just switch the glasses? Nov 1, 2022 at 0:03
• @Deusovi — No, don't worry about letter orientation. I had originally considered it, but quickly realized that keeping track of letter orientation would make the puzzle too tedious for everyone. Let's just say that because the ice cubes are bottom-heavy trapezoids, they will always orient themselves properly in midair when being poured! Nov 1, 2022 at 0:05
• @Deusovi — I guess it's wordplay because you are forming words? Nov 1, 2022 at 0:06
• @FlorianF — Let's just imagine that the first glass is chipped and the bartender wants to show off his elegant arrangement in perfect glasses. Nov 1, 2022 at 0:09

It can be in too many moves but it can be done.

Notation: To show a position I will display the glasses horizontally, with the bottom at the right. The three strings represent the glass content from top to bottom. Available empty space is represented by a -.

So we want to go from
ENJOY ----- THIS
to
----- ENJOY THIS

A sequence of moves is noted as number pairs, the source and destination glasses. For instance we could do the sequence 32 13 32:

ENJOY ----- THIS
ENJOY -SIHT ----
----Y -SIHT OJNE
----Y OSIHT -JNE

The solution involves a few steps.

Preparation:

First we free the 3rd glass with the move 32.
ENJOY ----- THIS
ENJOY -SIHT ----

If we manage to reverse the 'ENJOY' without disturbinb the 'SIHT', we can finish by transferring these to glasses 3 and 2 in the correct orientation.

First we define two move sequences:

Sequence A: 13 12 31 21:

ENJOY -SIHT ----
----Y -SIHT OJNE
----- YSIHT OJNE
-ENJO YSIHT ----
YENJO -SIHT ----

Sequence B: 13 32 31 21:

ENJOY -SIHT ----
----Y -SIHT OJNE
----Y OSIHT -JNE
-ENJY OSIHT ----
OENJY -SIHT ----

Sequence A rotates the 5 letters of the first glass. 'ENJOY' becomes 'YENJO'. Sequence B rotates only the first 4 letters of the first glass. 'ENJOY' becomes 'OENJY'. These two sequences can be combined to reverse the word 'ENJOY'.

Combination:

After the initial move, we execute the sequences: B B A B A B A A.

This affects the letter in the following way. Each line is the result of one sequence A or B.
ENJOY -SIHT ----
OENJY -SIHT ----
JOENY -SIHT ----
YJOEN -SIHT ----
EYJON -SIHT ----
NEYJO -SIHT ----
JNEYO -SIHT ----
OJNEY -SIHT ----
YOJNE -SIHT ----

Final:

As I said in the preparation, the final moves are just 23 12:

YOJNE -SIHT ----
YOJNE ----- THIS
----- ENJOY THIS

The number of moves is 1 for the preparation, 8x4 = 32 for the sequence of sequences, and 2 more final moves. That makes 35 moves in total. But I am pretty sure it can be done in fewer moves.

Update

A computer search returns solutions in 27 steps as 2012rcampion has found in the meantime.

It happens that one solution can be expressed using my A and B sequences.
If you do B A B A B B after the initial move, the effect is:

ENJOY -SIHT ----
OENJY -SIHT ----
YOENJ -SIHT ----
NYOEJ -SIHT ----
JNYOE -SIHT ----
OJNYE -SIHT ----
YOJNE -SIHT ----

Using this you get a solution with 1 + 6x4 + 2 = 27 moves.

• I love that you took a classic Rubik's cube approach, identifying sequences of moves that achieve certain things, and then stringing them together as needed to solve the puzzle. Nov 1, 2022 at 14:44

The shortest solutions have:

27 steps

One example is the following:

E .   | . Y   | . Y   | Y .   | . .   | E .   | E .
N . T | . O T | S O . | S O . | . O H | N . H | N Y .
J . H | . J H | I J . | I J . | . J I | J . I | J S .
O . I | . N I | H N . | H N . | . N S | O . S | O I .
Y . S | . E S | T E . | T E . | T E Y | T . Y | T H .

. .   | . O   | . O   | . .   | H .   | H .   | . .
. Y O | . Y . | E Y . | E . I | E . I | E O . | . O J
. S J | . S J | N S . | N . S | N . S | N Y . | . Y N
. I N | . I N | J I . | J . Y | J . Y | J S . | . S E
T H E | T H E | T H . | T H O | T . O | T I . | T I H

. J   | . J   | . .   | I .   | I .   | . .   | . N
. O . | H O . | H . S | H . S | H J . | . J N | . J .
. Y N | E Y . | E . Y | E . Y | E O . | . O E | . O E
. S E | N S . | N . O | N . O | N Y . | . Y H | . Y H
T I H | T I . | T I J | T . J | T S . | T S I | T S I

. N   | . .   | S .   | S .   | . .   | . E   | . E
I J . | I . Y | I . Y | I N . | . N E | . N . | . N T
H O . | H . O | H . O | H J . | . J H | . J H | . J H
E Y . | E . J | E . J | E O . | . O I | . O I | . O I
T S . | T S N | T . N | T Y . | T Y S | T Y S | . Y S

• The second move is illegal, see the rule about "Movement".
– Bass
Nov 1, 2022 at 4:38
• @Bass Of course, I forgot the state transition graph is directed... that's what I get for not double-checking my output Nov 1, 2022 at 6:10