2014-11-13 HW22 (hanoi)

posted Nov 13, 2014, 6:23 AM by Samuel Konstantinovich   [ updated Nov 13, 2014, 6:23 AM ]
HW22: Complete your hanoi function 
(hanoi start temp end n) ->  display a sequence of moves

The first 3 numbers are just labels
(hanoi 1 2 3 1)
1 to 3

(hanoi 1 2 3 2)
1 to 2
1 to 3
2 to 3

(hanoi 1 2 3 3)
1 to 3
1 to 2
3 to 2
1 to 3
2 to 1
2 to 3
1 to 3

The first 3 numbers are just labels
(hanoi 'a 'b 'c 2)
a to b
a to c
b to c


New functions:
begin
display
newline

Sample code using the 3 functions:

(define (foo n)
  (if (> n 0)
      (begin
         (display "Say hello " ) 
         (display n)
         (display " my little friend!")
         (newline)
         (foo (- n 1)))
      (display 'done)
      ))
(foo 5)
Comments