-----
If you recognize yourself in this description, you might include a couple of heady growth stocks in your portfolio, alongside your more pedestrian investments.
-----
先凭借昨天看 M.Hiroi San的做法留下的印象,今天自己先写一遍。
主要的印象是:
1)(multiple-value-bind vars value-form &body body) 里的这个对多个数值赋值,然后进行处理的函数。
2)check 的时候,不想我做减法,从一个 0~9 的集合里开始一项一项减,从一个空集合开始一项一项的加,有重复的元素就返回 check 的结果。
3)用了 do 来做主循环,自己完全不记得 do 的用法了。
先贴上自己的代码
(defun check-dts2 (a
&optional
(n (* a (+ a 1) (+ a 2)))
(nl '()))
(multiple-value-bind
(q r)
(truncate n 10)
(cond ((member r nl) ())
((= q 0) (format t "~D X ~D X ~D = ~D ~%"
a (+ a 1) (+ a 2) (* a (+ a 1) (+ a 2))))
(t (check-dts2 a q (cons r nl))))))
(defun solve-dts2 ()
(dotimes (x 1300 (format t "That's all.~%"))
(check-dts2 (+ 1000 x))))
昨天没有贴的运行结果是:
CL-USER> (solve-dts)
1267 X 1268 X 1269 = 2038719564
1332 X 1333 X 1334 = 2368591704
That's all.
NIL
再贴上搬来的代码:(http://www.geocities.jp/m_hiroi/xyzzy_lisp/abclisp12.html#chap25)
(defun solve ()
(do ((n 1007 (1+ n)))
((> n 2144))
(check n (1+ n) (+ n 2))))
(defun check (n1 n2 n3)
(let ((value (* n1 n2 n3)) numbers)
(dotimes (x 10 (format t "~D * ~D * ~D = ~D~%" n1 n2 n3 (* n1 n2 n3)))
(multiple-value-bind
(q r)
(truncate value 10)
(if (member r numbers) (return))
(push r numbers)
(setq value q)))))
再做比较就发现,印象和实际还是有蛮大区别的:
1)(do varlist endlist &body body)
2)(dotimes (var count &optional result) &body body)