In this set of exercises, we will devise an algorithm for the Tricolor Hanoi problem. There will be 3 stacks on 3 pegs, each stack of a differing color, and the problem is to exchange the stacks' positions under the classical move rules (one disk at a time, and no bigger disk over smaller disk).
As in previous exercises, our solution will use three functions:
move3(n, src, mid, dst)
: moves a stack of interleaved disks, ie a stack of (n*3) disks
of alternating colors from peg src
to peg dst
.gather()
: builds an interleaved stack from the regular split ones.scatter()
: splits an interleaved stack into several regular ones.The goal of this first exercise in the series is to devise the move3()
function.
This starter task should not block you for too long, actually. It is ok if your function changes
the order of the bottom triplet of disks, but it must preserve the order of the other triplets.