(defun hanoi (nn);;1st subroutine
(defun han (n x y z);;2nd sub
(if(>(- n 1)0) (han (- n 1) x z y));;if statement: if t then sub2
(terpri);;newline
(princ "From ")(princ x)(princ " to ")(princ z);;print "From 'x to 'z "
(if(>(- n 1)0) (han (- n 1) y x z));;if t then sub2
)
(han nn 'Peg1 'Peg2 'Peg3);;activate sub:
;;'han' input with variable x==peg1;y==peg2;z==peg3;n==nn
(terpri)(princ (-(expt 2 nn)1))(princ " moves.");;2^nn-1
(terpri);;newline
)
(hanoi 3);;activate sub: 'hanoi' input with variable nn=3
|