Problematic petrol

You have a 19-litre and a 13-litre petrol can. Both are empty at the start.

You can only do these:

  • Pour petrol from one can to another.
  • Completely empty or refill a can to its brim.

What is the least number of steps required to obtain exactly 8 litres of petrol in either cans?

Note: Filling, transferring or emptying is counted as one step.

Bonus challenge : Find the general method of solving when the volumes of the two cans are varied.

For example: To obtain 12 litres, we can start with the 19-litre can

  1. Fill the 19-litre one : 0, 19
  2. Transfer (to the left) : 13, 6
  3. Empty the 13-litre : 0, 6
  4. Transfer: 6, 0
  5. Refill: 6, 19
  6. Transfer: 13, 12

This will take a total number of 6 steps.


The answer is 14.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Cz Seow
Jun 21, 2018

++ means filling it to the brim

-- means emptying

--> means transfer to the right can

<-- means vice versa

You would realise that there are only ++ on the left, -- on the right and only -->,

because doing the opposite will always result in working backwards, which is counter-productive (you won't get new integers)

Whenever we transfer to the right we will get either (x, 19) or (0,y), where

0 < x < 13

0 < y < 19

(x, 19): If we empty the left, we will get (0, 19), deleting our ‘new value’ (not productive)

(0, y): If we fill the right, we will be ‘masking our new integer’ which does not help at all

Since we started with 13 and then transferred right, we cannot do otherwise but add on the left, empty the right and transfer right. This only allows us to do the same and so on.

General formula

Now, let's look at this geometrically/graphically:

This geometric representation follows the rule that we can only refill the left, transfer right and empty the right. I recommend you to study the graph and do some arithmetics to prove that it is an appropriate representation

After that, you will realise that this has something to do with modulus as the containers gets filled and emptied, just like the remainnder of x / 3 x/3

The arrows pointing down represent the 13-litre can

The ones pointing right represent the 19-litre can

A line of gradient 1 is drawn from the origin

At (0,0), the y-value matched the tip of vector AC, meaning that the 13 is full

The x-value matched the base of vector AB, meaning that the 19 is empty

When the graph y = x y=x touches vector AB, it means that 13-litres have been transferred (isosceles right angled triangle)

The y-value corresponds to the base of vector AC and the tip of vector DB, meaning that the left can is empty and it is going to be refilled

When the graph intersects vector DB, it means that an “emptiness” of 6 litres have been transferred from 19-litre can to the 13-litre can because vector AB and DB meet with their arrows pointing towards each other rather than away

This representation follows the rule that we can only add on the left, empty the right and transfer right in order to take the minimum number of steps

From the graph, we know that the 13-litre can is going to contain our desired integer first.

Every intersection point on the graph represents two things:

  • The refilling of 13-litre can
  • The emptying of the 19-litre can

Each vector of gradient 1 also represents the transferring step

Since the points land on the horizontal and vertical vectors, the number of points are equal to the number of horizontal and verical vectors

Hence, if we want to get 1 litre, the number of steps is equal to 4 intersecting points + 4 vectors of gradient 1 = 2 x 4 intersecting points = 2 x (2 horizontal + 2 vertical) = 8

Notice that I ignored the last point J since it implies emptying the 19-litre so I did not draw and count the last '13' vector

We can formulate this equation from the graph

19 a = 13 b + 12 19a=13b+12 rather than 19 a = 13 b 1 19a=13b-1 since we ignored the 3rd '13' vector

Note that the b b in the second equation is one more that the other b b in the first equation.

Where a and b are integers

a a represents the number of ‘19’ vectors

b b represents the number of ‘13’ vectors

This is also asking of what is the number that is divisible by 19 and leaves a remainder of 12 when divided by 13

The number is 38 and

a = 2 a=2 , b = 2 b=2

This is equal to 4 × 2 = ( a + b ) × 2 = 8 4\times2=(a+b)\times2=8 , which is proved correct

General method of solving:

Let x x and y y be the maximum integer volumes

Let a a and b b be integers

Let r r be the remaining volume you want to obtain

a x + ( x r ) = b y ax+(x-r)=by for starting with x

Solve for a a and b b using the Chinese Remainder Theorem

Add a a and b b then multiply then by 2 and there you go!!

Using the method to get a remainder of 8 litres:

13 a + 5 = 19 b 13a+5=19b

a = 4 a=4

b = 3 b=3

Ans: 14

We will get 46 if we started with 19

By the way, the graph can be compacted, being very similar to A lot of reflections

OKAY, now I understand! You are actually trading fullness of 13L can and emptiness of 19L can. Very clever idea, although your explanation could be better - it took me almost an hour to understand what you meant. Still great solution!

Uros Stojkovic - 2 years, 11 months ago
Edwin Gray
Jun 21, 2018

19 liter on the left, 13 liter on the right. (1) fill the right. (0,13) (2) transfer left (13,0) (3) fill the right (13.13) (4) transfer to left (6,7) (5) empty left (0,7) (6) transfer to left (7,0) (7) fill the right (7,13) (8) transfer to left (19,1) (9) empty the left (0,1)

(10)transfer to left (1,0)

(11) fill the right (1,13)

(12) transfer to left (14,0)

(13) fill the left (14,13)

(14) transfer to left (5,8). Ed Gray

X X
Jun 21, 2018
  1. Fill the 13-litre one : 13,0
  2. Transfer (to the right) : 0,13
  3. Fill the 13-litre one : 13,13
  4. Transfer (to the right) : 7,19
  5. Empty the 19-litre: 7,0
  6. Transfer : 0,7
  7. Refill : 13,7
  8. Transfer (to the right) : 1,19
  9. Empty the 19-litre : 1,0
  10. Transfer : 0,1
  11. Refill : 13,1
  12. Transfer (to the right) : 0,14
  13. Refill : 13,14
  14. Transfer : 8,19

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...