handasa Posted June 30, 2017 Author Posted June 30, 2017 BTW: Both my last suggestion and Lee's Chain do not work on: (setq ls3 '((B1 B2 B3 B4 B5) (B3 B4) (B2 B3) (B1 B2))) : (chain ls3) ((B4 B3 B2 B1 B2 B3 B4 B5)) : (List_To_Chains ls3) ((B1 B2 B3 B4 B5) (B2 B3 B4)) each item in my list is repeated at max 2 times ... so both of you and lee 's routines are working fine now ... Quote
Roy_043 Posted July 2, 2017 Posted July 2, 2017 (setq ls0 '((B8 B9) (B1 B2) (B6 B5) (B2 B1) (B3 B4) (B2 B3) (B6 B7) (B10 B11))) (setq ls1 '((B1 B2) (B3 B4) (B2 B3) (B1 B2))) (setq ls2 '((B1 B2) (B1 B2) (B3 B4) (B2 B3))) (setq ls3 '((B1 B2 B3 B4 B5) (B3 B4) (B2 B3) (B1 B2))) (setq ls4 '((B1 B2) (B3 B2) (B1 B2) (B3 B2) (B1 B2) (B3 B2) (B1 B2) (B3 B2))) ; (SubLists_To_Chains ls0) => ((B7 B6 B5) (B1 B2 B3 B4) (B8 B9) (B10 B11)) (defun SubLists_To_Chains (lst) (while (vl-some '(lambda (sub1) (vl-some '(lambda (sub2 / new) (if (setq new (List_Chain sub1 sub2)) (setq lst (cons new (vl-remove sub2 (vl-remove sub1 lst)) ) ) ) ) (vl-remove sub1 lst) ) ) lst ) ) lst ) ; (List_Chain '(B1 B2 B3 B4 B5) '(B1 B2)) ; (List_Chain '(B5 B4 B3 B2) '(B1 B2)) ; (List_Chain '(B5 B4 B3 B2) '(B3 B4)) ; (List_Chain '(B1 B2) '(B3 B2)) (defun List_Chain (lst1 lst2 / tmp pos) (if (> (length lst1) (length lst2)) (mapcar 'set '(lst1 lst2) (list lst2 lst1)) ) (if (not (vl-position (car lst1) lst2)) (setq lst1 (reverse lst1))) (while (and lst1 (setq tmp (vl-position (car lst1) lst2))) (setq pos tmp) (setq lst1 (cdr lst1)) ) (cond ((not pos) nil ) ((not lst1) lst2 ) ((zerop pos) (append (reverse lst1) lst2) ) (T (append lst2 lst1) ) ) ) Quote
handasa Posted July 8, 2017 Author Posted July 8, 2017 this one is excellent , Roy ... thanks man Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.