-----
If you are younger, and in a solid financial position, you may decide to take an aggressive approach
-- but only if you're blessed with sanguine disposition and won't suffer sleepless nights over share prices.
-----
接下来是一道关于大町数的题目,大町数是有 0-9 的 10 个数码各一个组成的数。
求所有乘积为大町数的三个连续整数的组合。
这个是自己写的。
(defun check-dts (a b c
&optional (n (* a b c))
(nl '(1 2 3 4 5 6 7 8 9 0)))
(let ((chkpoint1 (truncate n 10))
(chkpoint2 (mod n 10)))
(if (zerop (length nl))
(format t "~D X ~D X ~D = ~D ~%"
a b c (* a b c))
(unless (and (= chkpoint1 0) (= chkpoint2 0))
(when (find chkpoint2 nl)
(check-dts a b c chkpoint1 (remove chkpoint2 nl)))))))
(defun solve-dts (&optional (a 1000))
(let ((aaa (* a (+ a 1) (+ a 2))))
(cond ((< aaa 1023456789) (solve-dts (+ a 1)))
((> aaa 9876543210) (format t "That's all. ~%"))
(t (progn (check-dts a (+ a 1) (+ a 2))
(solve-dts (+ a 1)))))))
考虑三个数的乘积的范围在1023456789到9876543210之间,来作为递归调用结束的条件。
然后,从小到大把乘积算出来,一个个检验。
检验方法是从低位到高位拿出一位并从 0~9 的数组集合中去掉这个数字,如果最后集合被取空了,就判定成功。
M.Hiroi's 里面的解法很巧妙。
明天搬过来。