Welcome to a CT Challenge
A Solution
Abstract an Algorithm
Pseudo-Code
Sample Code in Python
Tkinter Code in Python
to display steps visually
You have to measure out 4 litres from containers of 7 litres and 5 litres.
The 4 litres must be contained in the smaller container at the end of the process, and the larger one empty.
You can :
1. Fill either container from a tap;
2. Empty one container into another until one is full or the other empty;
3. Empty a container into a sink.
The video shows a similar puzzle used in the Die Hard 3 movie.
It also shows a solution. Try to solve it before looking at the video.
The sandbox below can be used to run the sample Python code or to play around with your own ideas.
Be careful of certain limitations of online IDEs compared to those downloaded to your devices.