明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1089|回复: 4

[讨论] 如何按要求对表进行归类

[复制链接]
发表于 2016-1-29 13:19:56 | 显示全部楼层 |阅读模式

如图
需要对表中的数据进行归类,表中每个元长度一样,排列不一样,有什么办法找出该一定规律的元素呢

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

点评

Kye
这个是排列组合吧 4X3X2X1  发表于 2016-2-18 13:29
 楼主| 发表于 2016-2-18 12:57:35 | 显示全部楼层
有没有大神在线啊
发表于 2016-2-18 13:23:51 | 显示全部楼层
看不懂要求,看上去都一样。
发表于 2016-2-18 17:28:22 | 显示全部楼层
本帖最后由 ivde 于 2016-2-18 17:41 编辑

感觉递归代码简化些

  1. (defun tt (lst / conslst first nlst tf1 tf2)
  2.   (defun conslst (lst)
  3.     (cons (last lst) (reverse (cdr (reverse lst))))
  4.   )
  5.   (while lst
  6.     (if        nlst
  7.       (progn
  8.         (setq
  9.           nlst (mapcar '(lambda        (x / tf first llast tf1 tf2)
  10.                           (setq tf t)
  11.                           (while tf
  12.                             (setq first        (conslst (car x))
  13.                                   llast        (conslst (last x))
  14.                             )
  15.                             (if        (setq
  16.                                   tf1 (vl-member-if
  17.                                         '(lambda (x)
  18.                                            (equal first x 0.00001)
  19.                                          )
  20.                                         lst
  21.                                       )
  22.                                 )
  23.                               (setq x        (cons first x)
  24.                                     lst        (vl-remove first lst)
  25.                               )
  26.                             )
  27.                             (if        (setq
  28.                                   tf2 (vl-member-if
  29.                                         '(lambda (x)
  30.                                            (equal llast x 0.00001)
  31.                                          )
  32.                                         lst
  33.                                       )
  34.                                 )
  35.                               (setq x        (reverse (cons llast (reverse x)))
  36.                                     lst        (vl-remove llast lst)
  37.                               )
  38.                             )
  39.                             (if        (and (not tf1) (not tf2))
  40.                               (setq tf nil)
  41.                             )
  42.                           )
  43.                           x
  44.                         )
  45.                        nlst
  46.                )
  47.         )
  48.         (if lst
  49.           (progn
  50.             (setq first (conslst (car lst)))
  51.             (if        (vl-member-if
  52.                   '(lambda (x) (equal first x 0.00001))
  53.                   (cdr lst)
  54.                 )
  55.               (setq nlst (cons (list (car lst) first) nlst)
  56.                     lst         (vl-remove first lst)
  57.               )
  58.             )
  59.             (setq lst (cdr lst))
  60.           )
  61.         )
  62.       )
  63.       (progn
  64.         (setq first (conslst (car lst))) ;_back
  65.         (if (setq tf1 (vl-member-if
  66.                         '(lambda (x) (equal first x 0.00001))
  67.                         (cdr lst)
  68.                       )
  69.             )
  70.           (setq        nlst (cons (list (car lst) first) nlst)
  71.                 lst  (vl-remove first lst)
  72.           )
  73.         )
  74.         (setq second (append (cdar lst)
  75.                              (list (caar lst))
  76.                      )
  77.         ) ;_front
  78.         (if (setq tf2 (vl-member-if
  79.                         '(lambda (x) (equal second x 0.00001))
  80.                         lst
  81.                       )
  82.             )
  83.           (if nlst
  84.             (setq nlst (list (cons second (car nlst)))
  85.                   lst  (vl-remove second lst)
  86.             )
  87.             (setq nlst (cons (list (car lst) second) nlst)
  88.                   lst  (vl-remove second lst)
  89.             )
  90.           )
  91.         )
  92.         (if (and (not tf1) (not tf2))
  93.           (setq lst (cdr lst))
  94.         )
  95.       )
  96.     )
  97.   )
  98.   nlst
  99. )
_$ (tt '((1 2 3 4) (2 1 3 4) (1 4 3 2) (4 3 1 2) (3 4 2 1) (3 4 1 2) (4 1 2 3) (3 4 1 2)))
(((1 2 3 4) (4 1 2 3) (3 4 1 2)))
_$
 楼主| 发表于 2016-2-19 09:55:15 | 显示全部楼层
从来没研究过递归,学习了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-20 18:58 , Processed in 0.201137 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表