10-30-2013

posted Oct 30, 2013, 7:08 AM by Samuel Konstantinovich   [ updated Nov 1, 2013, 3:21 AM ]
More Hanoi!

Hanoi Process:  

One disk:
    Display <start> to <target>

More than one disk:
    1. Hanoi all disks on top of the bottom disk to the <temp>.
    2. Display <start> to <target>
    3. Hanoi all disks on <temp> to the <target>.

So basically

(hanoi n start temp end)

;This is pseudocode
if n = 1
    display start " to " end
else
   hanoi n-1 ? ? ?
   display start " to " end
   hanoi n-1 ? ? ?

So the code is going to look something like this:

(define (hanoi n start temp end)
    (if (= n 1)
             (begin
                (display start)
                (display " to ")
                (display end) 
                (newline)
             )
             (begin
                (hanoi ? ? ? ?)
                (display start)
                (display " to ")
                (display end) 
                (newline)
                (hanoi ? ? ? ?)
              )))

Comments