Lessons 6–10 · About 60 min per lesson

Step-by-step simulation

Update positions, capacities or scores in the prescribed order.

Lesson breakdown

  1. Lesson 6

    Represent the pebble’s position with one integer.

  2. Lesson 7

    Handle swaps when the position matches the left, the right or neither shell.

  3. Lesson 8

    Separate state updates from scoring after a move.

  4. Lesson 9

    Simulate pouring between containers, bounded by free capacity.

  5. Lesson 10

    Check unchanged states, repetitions and bounds on intermediate values.

Worked example

A pebble starts under shell 1. Swap 1 with 3, then 1 with 2. Where does the pebble finish?

How to solve it

The states are 1 → 3 → 3. The second swap does not involve the current position.

Assignment

Implement one pour, transferring as much as possible into the target, and return both new amounts.

Check your result

Source 7 and target 4 with capacity 6 → (5,6). A full target leaves both amounts unchanged.