### Author Topic: Fast search pairing algorithm  (Read 512 times)

0 Members and 1 Guest are viewing this topic.

#### well20152016

• Newt
• Posts: 75
##### Fast search pairing algorithm
« on: October 18, 2017, 08:09:06 PM »
Code - Auto/Visual Lisp: [Select]
`(setq l1(list (list '(89 1)'(99 3)'(45 4)'(67 7)'(54 5)'(33 3)) "A"))(setq l2(list (list '(39 1)'(33 9)'(27 1)'(84 8)'(13 7)'(99 5)) "B")Result:       (setq l3 (list (list '('(99 3)'(33 3)) "A")                         (list '('(99 5)'(33 9)) "B")		       ))`

#### ribarm

• Water Moccasin
• Posts: 2067
• Marko Ribar, architect
##### Re: Fast search pairing algorithm
« Reply #1 on: October 19, 2017, 04:27:36 AM »
Quick and perhaps slow...

Code - Auto/Visual Lisp: [Select]
`(defun foo ( l1 l2 / x2 l31 l32 l3 )  (foreach x1 (car l1)    (if (setq x2 (assoc (car x1) (car l2)))      (setq l31 (cons x1 l31) l32 (cons x2 l32))    )  )  (setq l31 (reverse l31) l32 (reverse l32))  (setq l3 (list (list l31 (cadr l1)) (list l32 (cadr l2))))  l3) `
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### well20152016

• Newt
• Posts: 75
##### Re: Fast search pairing algorithm
« Reply #2 on: October 19, 2017, 10:24:33 AM »
Code - Auto/Visual Lisp: [Select]
`(defun foo1 ( l1 l2 / a1 b1)(setq a1 (vl-remove-if-not '(lambda (x) (assoc (car x) (car l2))) (car l1)))(setq b1 (vl-remove-if-not '(lambda (x) (assoc (car x) a1))       (car l2)))(list (list (vl-sort a1 '(lambda (e1 e2)(< (car e1)(car e2)))) (cadr l1))      (list (vl-sort b1 '(lambda (e1 e2)(< (car e1)(car e2)))) (cadr l2))))`
« Last Edit: October 19, 2017, 10:35:08 PM by well20152016 »

#### roy_043

• Water Moccasin
• Posts: 1675