http://spin.atomicobject.com/05/31/use-clojure-to-move-drugs-a-programming-challenge/“rel="nofollow” http://spin.atobject.com/05/31/use-clojure-to-move-drugs-a-programming-challenge/ 和我跑进了一步。
采用复读算法(也许不是从正确选择开始)的Im,用最高至最低的数值对加权比率订购的“doll”构件。 相关法典是:
(defn get-carryable-dolls
[dolls carryable-dolls]
(def doll (first dolls)) ;initializing for use in multiple places
(def rest-dolls (rest dolls)) ;initializing for use in multiple places
(
if (will-fit? doll (get-weight-sum carryable-dolls))
( ;will fit
(
if
(= carryable-dolls {})
(def new-doll-set [doll]) ;First trip, get rid of empty set by initializing new
(def new-doll-set (flatten [doll carryable-dolls])) ;otherwise, flatten set into vector of structs
)
;tests to see if we have any more dolls to test, and if so, recurses. Otherwise, should pass the resultant vector
;up the stack. it appears to be the "else" potion of this if statement that is giving me problems.
(if (not= () rest-dolls) (get-carryable-dolls rest-dolls new-doll-set) (vec new-dolls))
)
( ;will not fit
;gets the rest of the dolls, and sends them on without modifying the vector of structs
;it appears to be the "else" potion of this if statement that is giving me problems.
(if (not= () rest-dolls) (get-carryable-dolls rest-dolls carryable-dolls) (vec carryable-dolls))
)
)
)
该法典正在正确运作;可回收的载体含有希望的重压载体,以作为解决办法回归。 不幸的是,当我试图将可回收的病媒退回到电话站时,我会发现以下错误:
CompilerException clojure.lang.ArityException: Wrong number of args (0) passed to: PersistentVector,compiling:(drugmover ests.clj:83)
第82-83段改为:
(def empty-dolls {})
(def designated-dolls (get-carryable-dolls sorted-values empty-dolls))
我对编辑错误中可能产生这一问题的推论感到困惑,由于Clojure似乎偏好对 st痕(或至少是Cloj的REPL功能)的透差错电,因此,我对如何加以纠正感到损失。 如果有人提出任何建议,我非常赞赏这些建议。
提前感谢。
<>光线>
我对守则进行了修改,提出了答复和评论中建议的办法,并提供了一些意见,以帮助说明正在进行的流动控制。 我希望,通过说明我的想法,有人能够给我一个我错了的想法。