X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Ftest%2Fhanoi.lisp;h=e2eb0fa00854dd3732496ca02e210feb8d142fc5;hb=30d6b241447cb922b9316e86817f6e31eb973eed;hp=d8ff2c86583220d3efbef3bc8856e87942cc50b2;hpb=d37945f1404043e6bd287ce7ad7a57bc3289609b;p=fw%2Faltos diff --git a/src/test/hanoi.lisp b/src/test/hanoi.lisp index d8ff2c86..e2eb0fa0 100644 --- a/src/test/hanoi.lisp +++ b/src/test/hanoi.lisp @@ -17,11 +17,11 @@ ; ANSI control sequences (defun move-to (col row) - (patom "\033[" row ";" col "H" nil) + (patom "\033[" row ";" col "H") ) (defun clear () - (patom "\033[2J" nil) + (patom "\033[2J") ) (defun display-string (x y str) @@ -43,18 +43,16 @@ (defun display-stack (x y clear stack) (cond ((= 0 clear) - (cond (stack (progn - (display-string x y (car stack)) - (display-stack x (1+ y) 0 (cdr stack)) - ) - ) + (cond (stack + (display-string x y (car stack)) + (display-stack x (1+ y) 0 (cdr stack)) + ) ) ) - (t (progn - (display-string x y " ") - (display-stack x (1+ y) (1- clear) stack) - ) - ) + (t + (display-string x y " ") + (display-stack x (1+ y) (1- clear) stack) + ) ) ) @@ -68,10 +66,9 @@ ; Display all of the stacks, spaced 20 columns apart (defun display-stacks (x y stacks) - (cond (stacks (progn - (display-stack x 0 (stack-pos y (car stacks)) (car stacks)) - (display-stacks (+ x 20) y (cdr stacks))) - ) + (cond (stacks + (display-stack x 0 (stack-pos y (car stacks)) (car stacks)) + (display-stacks (+ x 20) y (cdr stacks))) ) ) @@ -115,6 +112,8 @@ ; Move a piece from the top of one stack ; to the top of another +(setq move-delay 100) + (defun move-piece (from to) (let ((from-stack (nth stacks from)) (to-stack (nth stacks to)) @@ -124,7 +123,7 @@ (setq stacks (replace stacks from from-stack)) (setq stacks (replace stacks to to-stack)) (display) - (delay 100) + (delay move-delay) ) ) @@ -132,16 +131,12 @@ (defun _hanoi (n from to use) (cond ((= 1 n) - (progn - (move-piece from to) - nil) + (move-piece from to) ) (t - (progn - (_hanoi (1- n) from use to) - (_hanoi 1 from to use) - (_hanoi (1- n) use to from) - ) + (_hanoi (1- n) from use to) + (_hanoi 1 from to use) + (_hanoi (1- n) use to from) ) ) ) @@ -155,16 +150,6 @@ (setq len (reset-stacks)) (clear) (_hanoi len 0 1 2) - ) - - ; Run many in a row to time them - -(defun hanois(n) - (cond ((> n 0) - (progn - (hanoi) - (hanois (1- n)) - ) - ) - ) + (move-to 0 23) + t )