[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.

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.

1 Like

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.