[Community Puzzle] The water jug riddle from Die Hard 3

https://www.codingame.com/training/expert/the-water-jug-riddle-from-die-hard-3

Send your feedback or ask for help here!

4 posts were merged into an existing topic: The water jug riddle from die hard 3

Hello,

My program passes successfully all the ide tests, but fails the 3rd and 4th validators.
Is it possible te get the values of these validators please because i couldn’t figure out the issue without the data.

cheers.

Can you explain your thought process with writing your code?

my program passes all the ide test and 3/4 validators tests, it fails only the 3rd validator.
for now my program go in depth (perhaps i ll change that for a BFS if needed)
i also enhaced it with momoization and it never go in depth more than the current solution found.

Not a bad puzzle, but the “riddle from Die Hard 3” is much older than any of those films.

1 Like

I think this puzzle is not “very hard” at all. Some puzzles from middle level are harder.

I thought that some test cases - after submitting my solution - are going to fail because of performance with tests with 100 containers. But surprisingly they weren’t.
The number of containers is limited to just 5.

2 Likes

I agree with zolv. A naive solution worked from the get go which usually means the puzzle is not that hard. Especially when the description hints on how the states and transitions should be arranged.

1 Like

I’m stuck on this one!
I wrote a BFS algorithm, avoiding repetitions in the jug fillings, but my C# program is still too slow for the 4th test. The 3 first tests pass OK, but after 6 steps in the 4th test the number of cases grows quite a bit and I time out.

I don’t know which cases I should ditch, I feel like each manipulation could lead to the solution (except maybe from filling a jug if another one is already full? But I tried that and time-outed anyway).

This is definitely the easiest of the Very Hard puzzles so far. A simple BFS with priority queue ordered by the number of steps solved it on the first attempt.

Just wanted to mention, that the solution always needs the water in A SINGLE CONTAINER! This is not really mentioned in the text, its rather implicit.

I assumed, that I just have to get the exact amount of water together.

This would also be true with 2 or more containers, that sum up to the solution and in fact this yields solutions with even less steps. So i was confused when my algorithm turned out to compute false results with a lower number of steps until I realized.

I know in the original riddle the solution was to put the single canister on the sensor, but again, its not stated clearly in the text.

Hope this helps other people as well :slight_smile:

Would be nice to mention in the text, that a single container needs to hold the full target amount of water.