开发者

How to make this neighbor function?

开发者 https://www.devze.com 2023-01-27 11:47 出处:网络
I have this code: (defparameter fc #\\F) (defparameter bc #\\B) (defparamete开发者_Python百科r gap #\\G)

I have this code:

(defparameter fc #\F)
(defparameter bc #\B)
(defparamete开发者_Python百科r gap #\G)

(defun solp (seq)
    (if (eql fc (car seq))
        (not (if (listp (cdr seq))
                 (find bc (cdr seq))
                 (eql seq bc)))
        (solp (cdr seq))))

(defun heuristic (seq &optional (f 0)) 
    (if (eql nil seq) 
        0   
        (if (eql bc (car seq))
            (+ f (heuristic (cdr seq) f)) 
            (heuristic (cdr seq) (+ f 1)))))

(defun genneighbors (seq)

    ;seq == (fc fc gap bc bc) ===> neighbors == ( (gap fc fc bc bc)
    ;                                              (fc gap fc bc bc)
    ;                                               (fc fc bc gap)
    ;                                               (fc fc bc bc gap) )
    ;I can't figure out how to do this
)

I can't figure out how to code the genneighbors function. How do I access an element (2 | 1) slots before gap How to generate all four possible neighbors? Can someone give me some pointers?


All the functions from the CLHS chapters conses and sequences apply to lists.

Also note that it is good programming style (for various reasons) to name global variables like this: *bc*, *fc* and *gap*.

Also note that in newer code one often uses FIRST instead of CAR and REST instead of CDR.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号