There are many ways to solve this problem, such as using a breadth-first search to try all possibilities and find the shortest solution. However, one approach stands out as particularly elegant. Label the jars A, B, and C and let the number of marbles in a jar be denoted |A|, |B|, or |C|. As you label the jars, sort them so that |A| <= |B| <= |C|. Now, continuously execute the following loop: For i = 0 to infinity: If the ith smallest bit of |B| is set, move 2^i marbles from B into A. Otherwise, move 2^i marbles from C into A. At some point, this must empty jar B. The reason for this is as follows. Notice that at each step of the loop, the number of marbles in jar A doubles. This means that |A| is always a perfect power of two. The loop then scans the binary representation of |B|, and whenever the bit represented by |A| is set in |B|, removes that many marbles from |B|. Eventually, this will empty |B| by subtracting out all of the powers of two that sum up to it. This is not the most formal explanation, but it can be proven rigorously by induction.