English 中文(简体)
普通公屋中的 ha子
原标题:towers of hanoi in common lisp

我认为,这是一个含糊不清的问题,因为我不知道我首先做些什么,但这里是这样。

我不得不在使用清单的普通议会中回答 ha问题。 基本上,一项职能是列出扼杀(姓名),然后将其从Peg A移至Peg C,使用Peg B进行储存,使其与名单上的顺序相同。

I have never used lisp before and I find the syntax very hard to understand. This is my code so far goo function is the hanoi work

(defparameter A  ())
(defparameter B  ())
(defparameter C  ())


(defun findPeg (p1 p2) (cond ((= 0 (- 3 p1 p2))A)  
    ((= 1 (- 3 p1 p2))B) ((= 2 (- 3 p1 p2))C)))

(defun getnum (x) (cond ((equalp x A) 0)((equalp x B)1)((equalp x C) 2)))

(defun hanoi (x) (defparameter A x) (setlength A)(goo len A C B))

(defun setlength(x) (defparameter len (list-length x)))


(defun goo (leng from to via) 

    (cond ((= leng 1)(push (pop A) C)) ;base case


((goo (1- leng) from via to)(push (pop A)  B) ;say/do something i think


((goo (1- leng) via to from)(push (pop B) C) ;say/do something i think


))))

我的问题是充满休止的呼吁。 我对我应该做什么感到非常困惑。 我知道,我显然必须把第一个名单上的头几句移至另一个小标题,但我不知道究竟是怎样操纵名单。 我感到,像我一样,应该利用传入“ go”功能的变量,但我必须说明如何加以编辑,因为当我改变职能时,外部变量不会改变。

现在,我犯了错误。

* - SYSTEM::%EXPAND-FORM: (GOO (1- LENG) FROM VIA TO) should be a lambda expression

这是一个令人痛心的呼吁,因此我不知道为什么要说这一点。

Basically I just want some tips or tricks on where do continue or ever where to restart because I don t even know if my approach is a good one. Anything is greatly appreciated. Thanks

最佳回答

首先,在法国空研中心内部使用直径几乎永远不是正确的事情。

如果你想有一套复杂的变量,则使用LET(或简单地把你的正式参数称为你所指定的参数)。

第二,您在“全球业务协调”职能范围内有以下表格:<代码>(fun arg .)(fun arg ...)。 你们想要失去最外人。

问题回答

暂无回答




相关问题
Recursive same-table query in SQL Server 2008

I have the following table in a SQL Server 2008 database: Id Name ParentFolder -- ---- ------------ 1 Europe NULL 2 Asia NULL 3 Germany 1 4 UK 1 5 China ...

Finding a class within list

I have a class (Node) which has a property of SubNodes which is a List of the Node class I have a list of Nodes (of which each Node may or may not have a list of SubNodes within itself) I need to be ...

Selecting records during recursive stored procedure

I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...

热门标签