;; //ideone.com/vzncKq
(defstruct point x y)
(defun point+ (p q)
(make-point :x (+ (point-x p) (point-x q))
:y (+ (point-y p) (point-y q))))
(defun make-point-from-char (c)
(ecase c
(#\> (make-point :x 1 :y 0))
(#\v (make-point :x 0 :y 1))
(#\< (make-point :x -1 :y 0))
(#\^ (make-point :x 0 :y -1))))
(defun draw (chars)
(let ((scr (make-hash-table :test #'equalp)))
(loop for char across chars
for p = (make-point :x 0 :y 0)
then (point+ p (make-point-from-char char))
do (setf (gethash p scr) char))
;;
(destructuring-bind (min-x min-y
max-x max-y)
(loop for point being the hash-keys in scr using (hash-value char)
maximize (point-x point) into max-x
maximize (point-y point) into max-y
minimize (point-x point) into min-x
minimize (point-y point) into min-y
finally (return (list min-x min-y
max-x max-y)))
(loop for y from min-y upto max-y
do (loop for x from min-x upto max-x
for c = (gethash (make-point :x x :y y) scr)
do (princ (or c #\*)))
(terpri)))))
(loop while (listen)
do (draw (read-line))
(terpri))