We are almost ready to write the whole tricolor algorithm. We just need the scatter()
function, very inspired from the first one that we wrote for the
Split Hanoi problem. Assuming that your interleaved stack
is placed on the mid
peg, spread the disks over all pegs. Make sure to use move3()
an even
amount of time at each recursive level to ensure that the bottom disks are in the correct order.
As you can see, the initial situation is not the one expected by scatter()
. You first have to apply
gather()
and move3()
(twice to get the bottom triplet in the right order). These few steps
plus the new scatter()
function are enough to entirely solve the Tricolor Hanoi problem.