How not to Die Hard with Math

I am a mathematician and I like action movies Particularly Die Hard is one of my favourites You know action movies and there is one which has a couple of maths problems and one very famous one is In this clip, so just play the clip and then we talk about a little bit Careful don’t open it.
What I gotta open and it’s gonna be alright I told you not to open it! I trust you see the message It has a proximity circuit. So please don’t try Yeah, I got it. We’re not gonna run. How we turn this thing off? On the fountain there should be two jugs, do you see them, a 5 gallon and a 3 gallon? Fill one of the jugs with exactly four gallons of water and place it onto the scale and the timer will stop Must be precise one answer more or less will result in detonation if you’re still alive wait, wait a sec I don’t get it you get it
No It’s a problem 30 seconds Mean I’m pretty good at these things But I don’t know if this was the first time that somebody posed this problem. 30 seconds! I don’t know anyway, so let’s just have it really really close look what’s going on here We’ve got two containers – a five gallon container and a three gallon container and now Simon the villain tells us to make exactly four gallons of water just by pouring back and forth between those two containers. No 30 seconds. Well, we probably dead, but anyway Let’s just think about it and see whether we can figure out what’s going on there Alright So here’s a solution, okay? Here’s a solution, and I think anybody who actually thinks about this a little bit will come up with the solution Okay, so what we do is we fill up the five gallon container Then we pour as much as possible from the five gallon into the three gallon container so it leaves us with two gallons in the five and Fills up the other one completely okay? We’ve got two and three there Okay, what comes next well the next thing. We do is. We just get rid of those three? Then we fill the two into the empty one like that, then we fill up the five gallon container Like this, and then we pour as much as possible from the five into this one here well, there’s only one one gallon that fits in here so that gets us to four on that side. Finished, put it on and Well probably ten minutes by now, but you know we’re in heaven. We’re still putting it on Alright now. I’ve got a really really cute Mathematical way of solving this problem and lots of related problems, and I just want to tell you about that one Okay, it goes and actually goes with billiards mathematical billiards. It’s a special sort of billiards table Well if you have a look at it. It’s not rectangular like the billiards table. It’s kind of skewed right so there’s a 60 degree angle here and Well, what are we going to do? Well, first of all have a look at the dimension of this table dimensions kind of a giveaway? You know there’s three units kind of this way, and there’s five units going this way So it must have something to do with the volumes of the containers all right then what we’re going to do is we’re going to put billets ball in one of the corners and then we shoot it at 60 degrees and just see what it does okay, and Well, let’s see what it does right, so I’ll shoot it It bounces here, and it’s reflected off at 60 degrees And it bounces there It goes like that and over here and there and that’s actually our solution How is it our solution? Well? It’s maybe not apparent yet So let’s put in something else so what we think of here is if you think of this and that one here as like axes of a coordinate system like xy Okay, so if this is x and this is y then there’s the origin you know (0, 0) then we go over one This is gets us to (1, 0) then over to point (2, 0) and so on and up here is (0, 3) and they’re up in the Corners well 5 over and 3 up which is (5, 3) ok Okay, so let’s shoot our billiards ball again okay, so we put it there and Right at the [moment]. It says 5 0 and basically what it tells us is 2 fill this container all the way up So we do that Then we [should] Fill its ball like that and Then we’ll just read off the coordinates here two three which tells us that we should Pour water from here to there as much as possible Because there we go Alright now it gets reflected off down to there. So we’re now a (2, 0) which tells us We should get rid of the water in the three gallon containers. We get rid of that then follow it further, (0, 2) that means we’re pouring the water from left to right and Then we go over here. Which just means we’re filling the 5-gallon up all the way up and Then one more step and that tells us well Pour some water from the five-gallon into the other one and that leaves us with (4, 3) It’s exactly the solution that we came up with at the beginning so pretty neat Okay, well What if Simon had asked us to put one gallon of water on the scales? well then that Method he actually tells us what to do because what we do is. We just kind of Keep on going in keep on going so it’d be the ball kind of keeps on bouncing here And let’s just go all the way and you can actually see it goes across all the lines that I had here originally okay, and Well now if you have a really close look you can actually see that in this position here that Corresponds to one gallon being in here and nothing [being] in there, so you just take this this container for little scales And you’re okay now This one here corresponds to two gallons. So it could also have done two gallons if he had said two gallons No problem this one here says three gallons pretty obvious you can just fill up that one and put it on so it Would be a really easy puzzle so I mean Simon’s meaner than that Four gallons we can also do we’ve just done that five gallons easy But there’s more you can also see at this point in time There was five gallons in here and one in there So we could actually take both containers put them on a scale And that would be six gallons of water right and in this position here We have five gallons in here and two gallons in here. So that would give us seven gallons We could put that one on solve another puzzle And we could also do five plus three of course, eight. So all the numbers from one to eight We can actually do as this diagram shows us Okay, there’s more in here. I Was wondering actually? then isn’t there a Faster way to get to one as soon as we touch by one or one three without having to complete the graph Yeah, like so as soon as as soon as you touch as soon as you touch anyone you’re done. Okay? Touch anyone and you’re done. That’s fine. Yeah so there was my My friend colleague and cameraman giuseppe who just had the right thing to say All right now next thing is There’s lots more hiding in this diagram, and then you would imagine okay, so there’s a second solution here and the second solution Well, how does this come about well? You could actually start from here and start from there? Why don’t you just shoot the ball from there, and then what happens well? Let’s see (0, 3) Corresponds to filling that one up first remember before we filled that one up And then what kind of the water was kind of flowing in this direction You kind of always fill this one up and pour over there until it’s full and then you kind of get rid of stuff Right and now kind of the waters flowing in the opposite direction okay, okay? Now. We shoot the billiards ball down there Tells us transfer the water alright now. We shoot it up. There tells us fill that one up water is flowing from here, huh? Okay, next one five one so we pour as much as possible over here Gets us to five one okay, then What are we supposed to do now? Just get rid of that one no then? Transfer the one then fill up the three then You know just pour it in and you’ve got the other four. That’s the second solution It’s a bit longer than the first one, but also works pretty neat right Okay, what else is there? Well? I should really tell you why this works all right? Yeah, I’m the mathologer I’m not really happy about all this stuff Until I’ve got a really really good explanation for these things Okay, so how do we go explain this? Basically the method works because the individual bits That the path made of work. What I mean by this – let’s have a look at one of those connections here What does that connection actually stand for well it stands for? one of the jugs being completely empty the (5, 1) and the other one has something in it and then what this Connection stands for is Just filling that guy Which is empty all the way up and if you go the other way which might also happen it Just means you just emptied a completely full 5 Gallon Jug you know that’s it right and obviously if you’re in a in a state like this, if you’re in state (0, 1) you can go this way and if you’re in state
(5, 1) you can go there So this connection here stands for something that really works in reality, okay? That is the second kind of connection here, and that’s this one here It’s exactly the same sort of thing instead of filling an empty five Or empty a full five you’re now filling an empty three or emptying a full three okay? So exactly the same thing this sort of connection here corresponds to something that really works in reality, okay? I’ve got a third kind of connection. It goes this way Well as if this actually will become more complicated here the situation because well, you can have a connection like that You can also have something like this And it can be done there and there. So you know, what what’s going on here? Well for this one here to really see what’s what’s going on. It’s actually helpful to kind of go in little segments here so let’s start from here and just Go to this point here Okay, that’s actually three one, okay So it’s three over one over. So what what are we actually doing when we’re kind of moving along this this segment? well, we are kind of Pouring water out from the from the big one from the five gallon one and we’re filling it into the other one, right? So here we start with (4, 0). We’re going one down and one up total amount of water stays the same right and So we’re moving in this direction. We’re basically pouring water from here to there One segment here corresponds to one gallon that is busy making a transfer, and you hit the other side Well, you got exactly the right amount you can basically hitting this boundary so it’s going to work all right so it’s going to work This sort of transfer again Corresponds to something that you know happens in reality So these these two points when you actually connect them You know that that really works. Now the path of the billiards ball it’s just made up from these individual segments that work, right? so if we start out with something that we can actually achieve like a (5, 0) Then all the other bits are connected by a things that works or the whole thing has to work So we automatically do the right thing nothing can go wrong okay, what else? Well, at some point in time there’s going to be Die Hard 25 and Actually actually pride myself that I’m a little bit I looked quite similar to Bruce Willis So I’m going to see whether I can be Bruce Willis in Die hard 25, and then solve the problem with my method here so, but in Die Hard 25, there’s also going to be a Simon’s going to be back as out of prison by now. I don’t know actually if maybe he died, he probably died… You can check it? Okay Giuseppe is going to check it. He’s gonna check it on his iphone while I keep talking Anyway, so let’s say Simon’s back either from prison or from the dead, and he’s going to tell me well this time I’m going to make it harder for you I’m going to have a 6 gallon jug and a 15 gallon jug and what I want you to make is a 5 gallons of water Okay and I’m going to you know see whether my method actually works, right? So what I’m going to do is I’m going to make Up a billiards table that has the dimensions 15 and 6 and then I’m going to just run my ball again And I know well Fingers crossed and see what happens when I run my ball and actually I mean there’s a bit of a problem here because the Biltz ball actually doesn’t hit every single one of the points down here, so it doesn’t hit any one of the Doesn’t hit the one, doesn’t hit the two, it hits the three, not the four and not the five, hits the six and in fact All the coordinates that you come across here are multiples of three and That’s sort of true in General, so if you’ve got you know volumes here and there then What you can do is… what you have to do – is you basically take the greatest common divisor of the two numbers which? In this case is three and then all the volumes you can make up are just multiples of of the greatest common divisor Well, in this case we’re actually out of lucky. He said I was supposed to do a five account to a five There’s no, you know There’s no five anywhere in here that that’s going to work, so I actually have to think of something else I’d probably be dead 30 seconds. I won’t be able to think of anything else

100 thoughts on “How not to Die Hard with Math

  1. A very good algorithm but introducing Bezout's lemma would have made the perfect coda (and would explain why the (6, 15) case won't ever hit 5).

  2. That isn't a strategy for finding a solution but only for giving a visual representation of the solution once it is found because you have no way of deciding where on the grid to start.

    I prefer the intuitive method of saying, "well, I can only fill one container and pour it all, or as much as possible, into the other because that's the only way to know how much I have. And it turns out that you can start either with the 3 or the 5 container filled and either starting point leads to a solution.

  3. Why it most be on a equilateral triangle grid ?
    Does it mean if you have 3 bottles, then you need a square grid¿

  4. So I assume if the dimensions are coprime then any volume of water is achievable from one of the starting corners?

  5. The solution I thought of is to fill the 3 gallon, pour it into the 5. Repeat, stopping when the 5 is full – this will leave you with 1 gallon in the 3 tank. Pour that into the 5, fill the 3, pour it into the 5. 1+3=4

  6. quicker would be to use the 3g to fill the 5 using two of the 3 gallon. then there is 1gal left in the 3 gal. poor out everything in 5gal. then poor the 1 gal into the container and then just fill the 3 gal again to get 4 gallons.

  7. A) fill 5/5 then pour from it until 3/3 -> we get 2/5, empty 0/3, fill with remainder -> 2/3. fill again 5/5, pour from it until 3/3 -> remainder is 4/5 = win. work: fills: 2 pours:3 empties:1
    B) fill 3/3, pour over -> 3/5. fill again 3/3, pour from it until 5/5 -> remainder 1/3. empty 0/5, pour from other so 1/5. add another 3/3 and pour it over -> 4/5 = also win. work: fills: 3 pours:4 empties:1

    good vid. you reference all thet hings i like, math, simpsons, futurama, die hard… since i saw the movie i already thought about that a long time ago. 2 solutions come to mind, but i would say its physically impossible, since in 30 filling the jug and being carefully at the same time so you dont splash a little seems impossible for the process required. even with haste… think about it, you probably take around 10 secs to fill your a waterboiler…
    anway i liked it in the movie and i like it now 😀 riddles!

  8. The fountain has a steady flow rate and looks like it might be fast enough to fill in 30 seconds.
    As an alternative but risky method, count how long to fill the 3 gallon container (x seconds) and use the formula x + x/3 to fill the 5 gallon container to 4 gallons.

  9. If both containers are cube shaped then both containers are filled to a triangle shape in the two dimensional plane without spilling and pour the partial 3 gallon jug into the partial 5 gallon jug. 5/2 + 3/2 = 4

  10. How can you still add up 2 gallons to the small container from the big container and still have 2 gallons in the small container… so the size of the small container dosent matter… what's the size measurement difference of the 2 bloody containers. Total B.S. .. not to smart after all.. really ask yourself please ..sorry.

  11. Since it's greatest common divisor then presumably that means any 2 prime sized jugs can make any number from 1 to the sum of their sizes, ie a 5 and 17 gallon jug should give you the ability to make any number between 1 and 22?

  12. You can play with 3 jugs if you draw a 3D pyramid of tetrahedra and ask what happens. You fill a container, you are on one of the edges of the pyramid moving out. Then if you empty the jug, you actually have a choice of going down one face or the other, which corresponds to your choice of emptying water into one of two possible jugs. You have to go on until a jug is filled (maximum coordinate for that jug).
    Here is a video of problem with jugs of 12, 8 and 5 litres : can you make 6 litres? (not gallons, but the principle is the same). Can you make any of the amounts from 1 to 12?
    The author of the video also talks about the problem in the Die Hard 3 scene.

  13. This puzzle and two similar ones are featured in the final level of Tomb Raider: The Last Revelation. I really liked these puzzles as a kid.

  14. I wonder if you could extend this problem to more than 2 jugs and if so, extent the billiards table method to higher dimensions 😛

  15. Fill 5L -> put 5L into 3L -> in 5L remains 2L. empty the 3L, put 2L in 3L, fill 5L, put 1L into 2L (by filling the rest of 1L in 3L jar) from 5L and on the 5L remains 4L.

  16. I did it a different way. Fill the 3 and put it in the 5. Fill the 3 again and top up the five, leaving 1 in the 3. Empty the five, put the 1 from the 3 in the 5 and then fill the 3 and pour it into the 5, making 4.

  17. I'll try to figure it out, but would you describe why you must go all the way to the edges? (Not "because billiard ball must hit edge to bounce" but in terms of the whole methodology).

  18. Actually, you start at (0,0) (the two empty jugs) then proceed to (5,0). Also you might want to explain why you must start in a corner (each jug must be fully empty or fully filled). How do you extend the method to N jugs?

  19. Before I watch:
    You fill the 3 gallons, and pour it in the 5 gallon; you then fill the 3 gallon again and pour until you've filled the 5 gallon, there is now exactly 1 gallong left in the 3 gallon. You now pour all the contents from the 5 gallon and pour the 1 gallon in it, now fill the remaining 3 gallons in it, you now have exactly 4 gallons of water in the 5-gallon container.

  20. Sir, You are clearly putting those images in post production, so how exactly are you interacting with those images ? Pl. help me , I am trying to make this type of videos.

  21. 1. Fill the 5L and pour 3L into the 3L container. There are now 2L remaining in the 5L container.
    2. Throw away the water in the 3L container and pour the 2L from the 5L into the 3L container. Now you have room for 1L in the 3L container.
    3. Fill the 5L with water again and pour from it 1L into the 3L container which had 2L leaving you with 4 litres in the 5L container.

  22. The Euler characteristic X=1 for a cone, pinched torus or Riemann sphere. Q=2-X=1 gives the # of projective cross caps or Q genus, for 1 sided surfaces. This limit of 2 sided surfaces listed must be 1 sided as H=1-X/2 = 1-1/2 =1/2 would have half a handle or genus. This cone example has no torsion usually present in the homology of 1 sided surfaces, which is possible and this is the only such example I've found. Is this the classical example of a one sided surface having no torsion? Why is this impossible to google? Does this pseudo-manifold require relative homology to deal with the cone vertex singularity or is this all correct as stated above? Does this mean the light cone null space is 1 sided? Continue a normal thru the cone vertex on straight path. For continuity of the normal vector it must pass from the cone interior to exterior when crossing the vertex. Closing the cone in projective 3-D shows the normal stays on the same cone side(interior or exterior)when passing the ideal plane, so the switch of sides when passing straight thru the cone vertex remains intact. THE CONE NULL SPACE OF LIGHT IS 1 SIDED! Passing thru the vertex exchanges spacelike with timelike intervals, as well switching sub-light speed with tachions when moving off the cone surface.

  23. video

    SHELLS- SPHERES IN NUCLEI.The Nobel Prize in Physics 1963 Maria Goeppert Mayer, J. Hans D. Jensen,

  24. nice, but I would prefer a square based table, where you can travel in 8 directions 45°s apart, and only from edge to edge. Of course, you couldn't use the bottom-left top-right axis unless you had 2 pipes to fill the bottles exactly at the same rate. But you can achieve that with a timer too, so whatever.

  25. My approach was this:
    1st: Fill up the 3 gallon container.
    2nd: Pour the 3 gallons into the 5 gallon container.
    3rd: Fill up the 3 gallon container again.
    4th: pour as much as possible from the 3 gallon container into the 5 gallon container.
    5th: Empty the 5 gallon container.
    6th: Pour the rest of the 3 gallon container into the 5 gallon container.
    7th: Fill up the 3 gallon container.
    8th/Final step: Pour the 3 gallons into the 5 gallon container.

    Nice Video!

  26. Another way:
    (1) fill 3 -> pour them to 5;
    (2) fill the 3 again -> pour 2 to 5 = you have 1 left.
    (3) empty 5, pour 1 from 3 into 5, fill 3 and pour to 5 = you have 4.

  27. I came up with this: Fill up the five gallon with what's in the three gallon, repeat, you have one gallon in three gallon can. Pour out the five gallon, fill it with one gallon from three gallon can, fill the three gallon and pour it t five gallon.

  28. I can use the diagram to "multiply" the two vectors A, B (at 60 degrees) by then "closing the lid" i.e. edge AB formed by connecting A to B has area = n triangles. Obvious for A times A as you show in another video, but also true for A times B. Extrapolates to A x B x C (three vectors emanating from the corner of a regular tetrahedron). Just "close the lid" and the volume is in "tetravolume" units e.g. 2 x 2 x 5 = 20 tetravolumes. Different meaning of multiplication, but then maths are full of such repurposings.

  29. fill each full, pour out untill each is half full, then combine, half of 5 is 2.5, half of 3 is 1.5, 2.5 +1.5= 4

  30. 15gb and 6gb to 5 gallons: Fill the 15gb to the top. Cut a small hole near the bottom and let drain into the 6gb while timing and keeping the 15gb top under the fountain so that it stays full. When the 6gb is full, empty it and fill it again for 5/6 the time. 5 gallons exactly.

  31. i solved it differently. I poured 3 gallons into the 5 gallon container, refilled the 3 gallon, poured it into the 5 gallon. That left one gallon. I poured out the 5 gallon container, poured in the one gallon, then poured in three more gallons. Edit: now i've watched the video, i see he showed that one.

  32. Fill the 3 dump in 5, fill the 3 dump in 5 again -> 3 is left with 1L in it. Dump the 5, fill the 5 with the 3 leftover (1L). Fill the 3 dump in 5. 5 is 4 liters.

  33. Science is over-bearing On the other hand, humble and meek Spiritual processes, which no scientific instrument can measure, thank god, are a million times rarer than even a quark or a nano-second particle born of a proton-proton collision. Human mind and related mental capacities, which can be learnt and developed – can see the spiritual processes at work and feel the effect as absolute ecstacy and freedom. But science has swept everybody off their feet with artficial hi-tech junk, and nobody wants to learn spiritual science. Matter science has brain-washed people and they are now slaves of "Time" "Money" and "mathematics". Just talk to a teenager, who has been converted to a timid, matter-enslaved consumer.
    For more, go to: and spend some time reading. Start thinking for yourself. You are a thinker!

  34. Really great videos. At the end I missed the conclusion, that once we see that there is a common greatest divisor, we have the same problem in fact as 2 x 5 billiard table.

  35. Here's an interesting problem for you, you have a 3 and 4 gallon jug, you have 30 seconds and you have to put 8 gallons of water on the computer so it doesn't self destruct. Good Luck!

  36. well i must comment on this one!! i imagined my self in that scenario and saw the solution in a flash!, fill both the canisters full, pour half from each out, (a tie could be used as a string to determin the half way), 2.5+1.5=4, DONE!

  37. Thank you Mathologer for sharing your fun with mathematic.
    What about 3 buckets say , 3,5, 7 ? Then a 3 dimensional billard will do. We can see the solution on a 3 dimensional piramidal grid.
    What about n buckets with no common divisors, then a n dimensional billard will do…
    How to display the the n dimensional grid so that we can "see" the solutions?

  38. 1. Pour the 5 jug into the empty 3 jug leaving 2 in the 5 jug.
    2. Dump the 3 jug.
    3. Pour the remaining 2 from the 5 jug into the empty 3 jug
    4. Fill the 5 jug and top off the 2 gallons in the 3 jug leaving 4 in the 5 jug.

    Filling the jugs fast enough in the allotted time is the tricky part.

    Wait! Wait! All I have to do is top off the three jug with the…BOOM!

  39. Think outside the box. Just have your personal assistant robot calculate the weight of 4 gallons of water, and then have it push on the scale with the same amount of force. Oh wait, this is just an action movie and not a sci-fi (future) movie? I might have to rethink this.

  40. But if the jugs are different sizes, that means they'd have different weights. The scale can't tell the difference between 1 ounce of plastic and 1 ounce of water!

  41. I'll presume the the Mathologer could understand what the terrorists in the first Die Hard were saying in German?

  42. These puzzle appears in the Tomb Raider 4 videogame. It have 3 instances, asking for 2, 4 and 1 liter to be measured out of 3 and 5 waterbags.

  43. Math, WTF is that? you're speaking English, you're European, so you should pronounce it the English way "Maths" math is a bastardisation made by the Americans.

  44. It's fascinating that the method works, but I would like an explanation of why the figure is a parallelogram. Why does that shape work?

  45. if you take a cylinder at an angle and fill it until the bottom edge and top edge are at the same water level….then you filled half the cylinder…. so 2.5 +1.5 = 4

  46. Amazing video !
    I discovered this type of puzzle when I was young (a long, long time ago) in a book about Sam Loyd's puzzle.
    If I remember correctly, he used sometimes a third jug and the diagramm was truncated, but I forgot the details.
    Do you know ?

  47. Fill the 3 up, poor it into the 5, fill the three up again, fill as much possible into the five again leaving 1 in the 3 container, empty the 5, put the one into the 5, fill the three again and poor into the 5 so that there’s 4 in the five!

  48. Very very interesting !!!
    1. This video
    2. Youtube recommending this video after 4 years it's been posted

  49. I personally prefer doing it this way: fill the 3 gallon, put it in the 5 gallon, then again fill the 3 gallon, fill the 5 gallon all the way, dump out the 5 gallon, put the 1 gallon (from the 3 gallon) in the 5 gallon, fill the 3 gallon again and you got it.

Leave a Reply

Your email address will not be published. Required fields are marked *