You have a 19-litre and a 13-litre petrol can. Both are empty at the start.
You can only do these:
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
This will take a total number of 6 steps.
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.
++ 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
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 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:
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
1 9 a = 1 3 b + 1 2 rather than 1 9 a = 1 3 b − 1 since we ignored the 3rd '13' vector
Note that the b in the second equation is one more that the other b in the first equation.
Where a and b are integers
a represents the number of ‘19’ vectors
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 , b = 2
This is equal to 4 × 2 = ( a + b ) × 2 = 8 , which is proved correct
General method of solving:
Let x and y be the maximum integer volumes
Let a and b be integers
Let r be the remaining volume you want to obtain
a x + ( x − r ) = b y for starting with x
Solve for a and b using the Chinese Remainder Theorem
Add a and b then multiply then by 2 and there you go!!
Using the method to get a remainder of 8 litres:
1 3 a + 5 = 1 9 b
a = 4
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