You have two containers. One can hold 7 liters of water and the other can hold 11 liters. You also have access to a sink with a faucet. You can do any of these three things as many times as you like:
- Fill one of the containers to the top with water.
- Completely empty one of the containers into the sink.
- Pour the contents of one container into the other until the second container is full (or until the first container is empty).
Given these conditions, is it possible to measure out exactly 5 liters of water? How?
- If the first bottle is empty, fill it until it's full
- If the first bottle is full, transfer the water to the second bottle
- Once the second bottle is full, empty it
- Repeat until either of the bottle has 5 liters
$ kotlinc simulation.kt -include-runtime -d simulation.jar
$ java -jar simulation.jar