Author Topic: {Resolved}How to find the duplicate items in the list  (Read 13400 times)

0 Members and 1 Guest are viewing this topic.

xiaxiang

  • Guest
Re: {Challenge}How to find the duplicate items in the list
« Reply #15 on: January 15, 2015, 04:34:51 AM »
Quote
OK, here's an iterative + imperative attempt by first sorting the list:
Code: [Select]
_$ (List:DuplicatesEq2 '(1.0 1.1 1.19 1.2 1.21 1.22 1.23 1.25 1.3 ) 0.05)
((1.19 1.2 1.21 1.22 1.23 1.25))
_$ (List:DuplicatesEq2 '(1.0 1.1 1.19 5.0 5.01 4.98 1.2 1.21 1.22 1.23 1.3) 0.05)
((1.19 1.2 1.21 1.22 1.23) (4.98 5.0 5.01))
Minor error
Code: [Select]
(List:DuplicatesEq2 '(1.0 1.1 1.19 1.2 1.2 1.21 1.22 1.23 1.25 1.3 2.0 2.1 2.19 2.2 2.2 2.21 2.22 2.23 2.25 2.3) 0.05)
-->((1.19 1.2 1.2 1.21 1.22 1.23 1.25) (2.19 2.2 2.2 2.21 2.22 2.23 2.25 2.3))
« Last Edit: January 15, 2015, 04:51:30 AM by xiaxiang »

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: {Challenge}How to find the duplicate items in the list
« Reply #16 on: January 15, 2015, 04:40:37 AM »
Minor error
Code: [Select]
(List:DuplicatesEq2 '(1.0 1.1 1.19 1.2 1.2 1.21 1.22 1.23 1.25 1.3 2.0 2.1 2.19 2.2 2.2 2.21 2.22 2.23 2.25 2.3) 0.05)
-->((1.19 1.2 1.2 1.21 1.22 1.23 1.25) (2.19 2.2 2.2 2.21 2.22 2.23 2.25 [color=red]2.3[/color]))

On my comp:
Code: [Select]
  (equal 2.25 2.3 0.05);=>> T
  (equal 2.15 2.2 0.05);=>> nil
  (equal 2.05 2.1 0.05);=>> nil
:-(

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: {Challenge}How to find the duplicate items in the list
« Reply #17 on: January 15, 2015, 04:43:26 AM »
my version for sorted list:
Code - Auto/Visual Lisp: [Select]
  1. (defun f (l a b)
  2.   (cond ((and (not l) (cdr b)) (list (reverse b)))
  3.         ((not l) nil)
  4.         ((equal (car l) (car b) a) (f (cdr l) a (cons (car l) b)))
  5.         ((cdr b) (cons (reverse b) (f l a nil)))
  6.         ((f (cdr l) a (list (car l))))
  7.   )
  8. )
test:
Code - Auto/Visual Lisp: [Select]
  1. (f (vl-sort l '<=) a nil)

xiaxiang

  • Guest
Re: {Challenge}How to find the duplicate items in the list
« Reply #18 on: January 15, 2015, 04:55:33 AM »
my version for sorted list:
Code - Auto/Visual Lisp: [Select]
  1. (defun f (l a b)
  2.   (cond ((and (not l) (cdr b)) (list (reverse b)))
  3.         ((not l) nil)
  4.         ((equal (car l) (car b) a) (f (cdr l) a (cons (car l) b)))
  5.         ((cdr b) (cons (reverse b) (f l a nil)))
  6.         ((f (cdr l) a (list (car l))))
  7.   )
  8. )
test:
Code - Auto/Visual Lisp: [Select]
  1. (f (vl-sort l '<=) a nil)

What is "a" and "b"? :-o

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: {Challenge}How to find the duplicate items in the list
« Reply #19 on: January 15, 2015, 05:03:37 AM »
What is "a" and "b"? :-o

Code: [Select]
(f (vl-sort '(1.0 1.1 1.19 1.2 1.2 1.21 1.22 1.23 1.25 1.3 2.0 2.1 2.19 2.2 2.2 2.21 2.22 2.23 2.25 2.3)  '<=) 0.05 nil)

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: {Challenge}How to find the duplicate items in the list
« Reply #20 on: January 15, 2015, 05:49:00 AM »
On my comp:
Code: [Select]
  (equal 2.25 2.3 0.05);=>> T
  (equal 2.15 2.2 0.05);=>> nil
  (equal 2.05 2.1 0.05);=>> nil
:-(
but
Quote
(equal 2.25 (+ 2.25 0.05) 0.05);=>> T
(equal 2.15 (+ 2.15 0.05) 0.05);=>> T
(equal 2.05 (+ 2.05 0.05) 0.05);=>> T
damn nice surprise from autodesk programmers :)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: {Challenge}How to find the duplicate items in the list
« Reply #21 on: January 15, 2015, 06:05:00 AM »
Sorry for the intrusion, but there is something I do not understand. If we, for example, stating that this function is reliable:
Code: [Select]
;; Unique with Fuzz  -  Lee Mac
;; Returns a list with all elements considered duplicate to
;; a given tolerance removed.
(defun LM:UniqueFuzz ( l f / x r )
    (while l
        (setq x (car l)
              l (vl-remove-if (function (lambda ( y ) (equal x y f))) (cdr l))
              r (cons x r)
        )
    )
    (reverse r)
)
Code: [Select]
(LM:UniqueFuzz     '(1.0 1.1 1.19 1.2 1.21 1.22 1.23 1.25 1.3) 0.05)
=>                  (1.0 1.1 1.19                    1.25 1.3)
So: (1.2 1.21 1.22 1.23) are duplicates? This is the required result?
Code: [Select]
; 20150114 - 1.00 - only for test
(defun ALE_List_FindDupesFuzz (In_Lst FuzFac / OutLst TmpLst NthVal Countr)
    (setq OutLst (list (car In_Lst)) In_Lst (cdr In_Lst))
    (foreach ForElm In_Lst
      (if (vl-position ForElm OutLst)
        OutLst
        (progn
          (setq Countr 0)
          (while (and Countr (setq NthVal (nth Countr OutLst)))
            (if (equal ForElm NthVal FuzFac)
              (setq Countr nil)
              (setq Countr (1+ Countr))
            )
          )
          (if NthVal
            (setq TmpLst (cons ForElm TmpLst))
            (setq OutLst (cons ForElm OutLst))
          )
        )
      )
    )
    (reverse TmpLst)
)
(ALE_List_FindDupesFuzz '(1.0 1.1 1.19 1.2 1.21 1.22 1.23 1.25 1.3) 0.05)
(1.2 1.21 1.22 1.23)

xiaxiang

  • Guest
Re: {Challenge}How to find the duplicate items in the list
« Reply #22 on: January 15, 2015, 06:38:37 AM »
(1.19 1.2 1.21 1.22 1.23 1.25) are duplicate items in my case.The next step we will determine which value that was considered as duplicate should be reserved.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: {Challenge}How to find the duplicate items in the list
« Reply #23 on: January 15, 2015, 09:10:48 AM »
(1.19 1.2 1.21 1.22 1.23 1.25) are duplicate items in my case.The next step we will determine which value that was considered as duplicate should be reserved.
Ok, this may be a foreach version:
(ALE_List_FindDupesFuzz '(1.0 1.1 1.19 1.2 1.21 1.22 1.23 1.25 1.3) 0.05)  => (1.19 1.2 1.21 1.22 1.23 1.25)
Code: [Select]
; 20150115 - 1.03
(defun ALE_List_FindDupesFuzz (In_Lst FuzFac / OutLst TmpLst NthVal Countr)
  (setq OutLst (list (car In_Lst)) In_Lst (cdr In_Lst))
  (foreach ForElm In_Lst
    (if (vl-position ForElm OutLst)
      (or (vl-position ForElm TmpLst) (setq TmpLst (cons ForElm TmpLst)))
      (progn
        (setq Countr 0)
        (while (and Countr (setq NthVal (nth Countr OutLst)))
          (if (equal ForElm NthVal FuzFac) (setq Countr nil) (setq Countr (1+ Countr)))
        )
        (or
          Countr
          (progn
            (or  (vl-position NthVal TmpLst) (setq TmpLst (cons NthVal TmpLst)))
            (and (vl-position NthVal OutLst) (setq OutLst (vl-remove NthVal OutLst)))
          )
        )
        (if NthVal (setq TmpLst (cons ForElm TmpLst)) (setq OutLst (cons ForElm OutLst)))
      )
    )
  )
  (reverse TmpLst)
)

ronjonp

  • Needs a day job
  • Posts: 7526
Re: {Challenge}How to find the duplicate items in the list
« Reply #24 on: January 15, 2015, 09:34:14 AM »
Minor error
Code: [Select]
(List:DuplicatesEq2 '(1.0 1.1 1.19 1.2 1.2 1.21 1.22 1.23 1.25 1.3 2.0 2.1 2.19 2.2 2.2 2.21 2.22 2.23 2.25 2.3) 0.05)
-->((1.19 1.2 1.2 1.21 1.22 1.23 1.25) (2.19 2.2 2.2 2.21 2.22 2.23 2.25 [color=red]2.3[/color]))

On my comp:
Code: [Select]
  (equal 2.25 2.3 0.05);=>> T
  (equal 2.15 2.2 0.05);=>> nil
  (equal 2.05 2.1 0.05);=>> nil
:(

Same here .. that's not cool.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: {Challenge}How to find the duplicate items in the list
« Reply #25 on: January 15, 2015, 09:49:47 AM »
Minor error
Code: [Select]
(List:DuplicatesEq2 '(1.0 1.1 1.19 1.2 1.2 1.21 1.22 1.23 1.25 1.3 2.0 2.1 2.19 2.2 2.2 2.21 2.22 2.23 2.25 2.3) 0.05)
-->((1.19 1.2 1.2 1.21 1.22 1.23 1.25) (2.19 2.2 2.2 2.21 2.22 2.23 2.25 [color=red]2.3[/color]))

On my comp:
Code: [Select]
  (equal 2.25 2.3 0.05);=>> T
  (equal 2.15 2.2 0.05);=>> nil
  (equal 2.05 2.1 0.05);=>> nil
:(

Same here .. that's not cool.
Code: [Select]
(equal 2.25 2.30 0.05)                ;=>> T
(equal 2.25 2.30 0.049999999999999)   ;=>> nil
(equal 2.25 2.30 0.0499999999999999)  ;=>> T

(equal 2.15 2.2 0.05)                 ;=>> nil
(equal 2.15 2.2 0.0500000000000001)   ;=>> nil
(equal 2.15 2.2 0.050000000000001)    ;=>> T
:?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: {Challenge}How to find the duplicate items in the list
« Reply #26 on: January 15, 2015, 11:59:35 AM »
there is still something wrong...
Code: [Select]
(setq fuzz 0.05   alist '(3.0 1.0 1.1 1.19 1.2 1.21 1.22 3.0 3.0 3.0 3.0 3))
=> (3.0 1.0 1.1 1.19 1.2 1.21 1.22 3.0 3.0 3.0 3.0 3)

(ALE_List_FindDupesFuzz alist fuzz)  >>>  r.1.03
=>  (1.19 1.2 1.21 1.22 3.0 3)

(f (vl-sort alist  '<=) fuzz nil)
=> ((1.19 1.2 1.21 1.22) (3 3.0 3.0 3.0 3.0 3.0))

(List:DuplicatesEq alist fuzz)
=> (3.0 1.19 1.2 1.21 1.22 3.0 3.0 3.0 3.0 3)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: {Challenge}How to find the duplicate items in the list
« Reply #27 on: January 15, 2015, 01:10:37 PM »
On my comp:
Code: [Select]
  (equal 2.25 2.3 0.05);=>> T
  (equal 2.15 2.2 0.05);=>> nil
  (equal 2.05 2.1 0.05);=>> nil
:-(
but
Quote
(equal 2.25 (+ 2.25 0.05) 0.05);=>> T
(equal 2.15 (+ 2.15 0.05) 0.05);=>> T
(equal 2.05 (+ 2.05 0.05) 0.05);=>> T
damn nice surprise from autodesk programmers :)
This problem is caused by the fact that the 64 bit binary floating point format cannot be exactly matched to the decimal format.

xiaxiang

  • Guest
Re: {Resolved}How to find the duplicate items in the list
« Reply #28 on: January 19, 2015, 10:05:16 PM »
Thank you all !
 :-D :-D :-D

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: {Resolved}How to find the duplicate items in the list
« Reply #29 on: January 20, 2015, 08:47:01 AM »
IMHO, I think to properly terminate this thread need to distinguish three types of "ListDupesFuzz" functions:
Code: [Select]
=> fuzz 0.05

Remove Uniques: (1.0 1.1 1.19 1.2 1.21 1.22 1.23 1.25 1.3 3.0 3.0 3.0)
              =>(1.2              1.21 1.22 1.23)

Show     Dupes: (1.0 1.1 1.19 1.2 1.21 1.22 1.23 1.25 1.3 3.0 3.0 3.0)
             => (        1.19 1.2 1.21 1.22 1.23 1.25     3.0)

Show All Dupes: (1.0 1.1 1.19 1.2 1.21 1.22 1.23 1.25 1.3 3.0 3.0 3.0)
             => (        1.19 1.2 1.21 1.22 1.23 1.25     3.0 3.0 3.0)