You are on page 1of 1

Assignment1:

Instruction: Write an algorithm to solve the problem below.

PROBLEM: Suppose you have 2 jars, jar A and jar B, with unknown
number of identical marbles. Your task is to swap the contents (number
of marbles) of the 2 jars without using any other jar or container.
Example, jar A has 5 marbles while jar B has 3. After swapping, jar A
has now 3 marbles while jar B has 5. See below sample illustration.
Indicate, if any, exemption or limitations of your solution.

AFTER
SWAPPING

A B A B

You might also like