October 12th Friday (十月 十二日 金曜日

How to work out the enclosure sets of a set?  I implemented it in Emacs-lisp.  The source is as follow.

(setq empty-set (list nil))

(defun remove-dup (l)
  (defun rm-dup (ls rs)
    (cond ((null ls) rs)
  ((not (in-set (car ls) (cdr ls)))
   (rm-dup (cdr ls) (cons (car ls) rs)))
  (t (rm-dup (cdr ls) rs))))
  (rm-dup l nil))

(defun removed-one-subsets (s)
  (mapcar (lambda (e)
    (remove e s)) s))

(defun removed-one-subsets-from-sets (ss)
  (let ((rs nil))
    (while (not (null ss))
      (mapcar (lambda (x)
(setq rs (cons x rs)))
      (removed-one-subsets (car ss)))
      (setq ss (cdr ss)))
    (remove-dup rs)))

(defun enclosure-sets (set)
  (let ((n (length set))
(rs (list set))
(ss (removed-one-subsets set)))
    (setq rs (append rs ss))
    (while (> n (- (length set) 2))
      (setq ss (removed-one-subsets-from-sets ss))
      (setq rs (append rs ss))
      (setq n (- n 1)))
    (remove-dup (append rs empty-set))))

(enclosure-sets (list 1 2 3))
  => (nil (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3))

  The codes is not beautiful.  I discussed about the problem with my a workmates.  He thinks it easy to
implement.  But it does not seem to be easy in reality.  If try to combine ones that is extracted from the
original set, you have to met lots of problems, such as how to get one or more elements from a set and how to
combine more elements.  So, I adapted another way to remove one or more elements from the original set for
making a new sub-set.  The sub-set can also repeat deleting its elements until there are all one element sets.

  What is more, generally, a set doesn't include duplicated elements.  However, during working out the
enclosure-sets, there are some temporary sets or set have duplicated elements.  So, I wrote the function
remove-dup to make a new set or list from the original set or list that have not duplicated elements.

  Finally, don't forget appending a empty-set and the original set into the enclosure-set.

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值