anchor.diff:                              (LEFT 'RIGHT))
                             '(UP DOWN RIGHT LEFT))))))
   
  -
   (defun n-puzzle (search heuristic initial-state)
     (funcall search #'action heuristic #'goalp initial-state))
   
  
positive.code: 
  (defun A*-search (action heuristic goalp initial-state)
    (labels ((expand (node fringe)
               (remove-if (lambda (new-node)
                            (fringe-existp fringe new-node))
                          (mapcar (lambda (triple)
                                    (let* ((state (aref triple 0))
                                           (direction (aref triple 1))
                                           (cost (funcall heuristic state))
                                           (depth (1+ (node-depth node)))
                                           (pos-0 (aref triple 2)))
                                      (make-node :state state
                                                 :parent node
                                                 :direction direction
                                                 :path-cost (+ depth cost)
                                                 :depth depth
                                                 :pos-0 pos-0)))
                                  (funcall action node))))
             (search-iter (fringe)
               (let ((node (fringe-remove fringe)))
                 (if (funcall goalp (node-state node))
                     (list (direction-sequence node) (node-depth node))
                   (search-iter (fringe-insert fringe (expand node fringe)))))))
      (search-iter (fringe-insert (make-fringe :key #'node-path-cost)
                                  (list (make-node :state initial-state
                                                   :path-cost (funcall heuristic initial-state)
                                                   :pos-0 (position 0 initial-state)))))))
  
negative.code:                    (debug 0)))
  
  (defstruct fringe
    (state #'identity :type function :read-only t)
    (key #'identity :type function :read-only t)
    (elements (make-array 1024 :fill-pointer 0 :adjustable t) :type array)
    ;; Shadow slots, only can be modified by #'fringe-*.
    (minimum 0 :type integer)
    (hash-elements (make-hash-table)))
  
  (defun fringe-exist-state-p (f state)
    (let ((hash-elements (fringe-hash-elements f)))
      (gethash state hash-elements)))
  
  (defun fringe-remove (f)
    (let ((elements (fringe-elements f))
  