(defun find_smallest(row col cnt) (setq temprow 0) (setq tempcol 0) ;Trace back the same path if there is no where to go (cond ((and (< (+ col 1) 10) (numberp (aref labyrinth row (+ col 1)))) (cond ((= (- cnt 1) (aref labyrinth row (+ col 1))) (setq temprow row) (setq tempcol (+ col 1))) ) ) ((and (< (+ row 1) 10) (numberp (aref labyrinth (+ row 1) col))) (cond((= (- cnt 1) (aref labyrinth (+ row 1) col)) (setq temprow (+ row 1)) (setq tempcol col)) ) ) ((and (> (- row 1) -1) (numberp (aref labyrinth (- row 1) col))) (cond((= (- cnt 1) (aref labyrinth (- row 1) col)) (setq temprow (- row 1)) (setq tempcol col)) ) ) ((and (> (- col 1) -1) (numberp (aref labyrinth row (- col 1)))) (cond ((= (- cnt 1) (aref labyrinth row (- col 1))) (setq temprow row) (setq tempcol (- col 1))) ) ) ) (setq cnt (- cnt 1)) (setf (aref labyrinth row col) 'J) (setq row temprow) (setq col tempcol) (setf (aref labyrinth row col) '>) ; Returns the traced path row col and cnt value (cons row (cons col cnt)) )