Author Topic: Group list of numbers by fuzz value  (Read 1793 times)

0 Members and 1 Guest are viewing this topic.

agnesika

  • Mosquito
  • Posts: 2
Group list of numbers by fuzz value
« on: June 25, 2024, 03:02:37 AM »
Hello everyone,
I am looking for some similar function like in this topic, that will process a list of numbers numbers and group them by fuzz value.
For example:

Code - Auto/Visual Lisp: [Select]
  1. (setq lst '(500 500.02 125.03 125 300.01 300 450 455.02 455.7))
  2. (setq fuzz 0.1)
  3.  
  4. (GroupWithFuzz fuzz lst)
  5. Should return:
  6. '((500 500.02) (125.03 125) (300.01 300) (450) (455.02) (455.7))

dgpuertas

  • Newt
  • Posts: 87
Re: Group list of numbers by fuzz value
« Reply #1 on: June 25, 2024, 06:34:45 AM »
Lee mac write group - by function and i think is good for you purpose.

Code - Auto/Visual Lisp: [Select]
  1. (defun LM:GroupByFunction (lst fun / tmp1 tmp2 x1)
  2.   (if (setq x1 (car lst))
  3.     (progn
  4.       (foreach x2 (cdr lst)
  5.         (if (fun x1 x2)
  6.           (setq tmp1 (cons x2 tmp1))
  7.           (setq tmp2 (cons x2 tmp2))
  8.         )
  9.       )
  10.       (cons (cons x1 (reverse tmp1))
  11.             (LM:GroupByFunction (reverse tmp2) fun)
  12.       )
  13.     )
  14.   )
  15. )

You can use:
EDITED, Thanks Ribarm, i think its not necesary function, simple lambda
Code - Auto/Visual Lisp: [Select]
  1. (defun GroupWithFuzz (fuzz lst)
  2.   (LM:GroupByFunction lst (lambda (a b) (equal a b fuzz))  )
  3. )
  4.  
« Last Edit: June 25, 2024, 11:40:42 AM by dgpuertas »

ribarm

  • Gator
  • Posts: 3327
  • Marko Ribar, architect
Re: Group list of numbers by fuzz value
« Reply #2 on: June 25, 2024, 08:13:50 AM »
You can use:

Code - Auto/Visual Lisp: [Select]
  1. (defun GroupWithFuzz (fuzz lst)
  2.   (LM:GroupByFunction (lambda (a b) (equal a b fuzz)) lst)
  3. )
  4.  

You meant :

Code - Auto/Visual Lisp: [Select]
  1. (defun GroupWithFuzz (fuzz lst)
  2.   (LM:GroupByFunction lst (function (lambda (a b) (equal a b fuzz))))
  3. )
  4.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

dexus

  • Bull Frog
  • Posts: 232
Re: Group list of numbers by fuzz value
« Reply #3 on: June 25, 2024, 09:21:37 AM »
Note that the rounding gives different result for when the list is ordered differently. This is an edge-case of course.

Here are two lists, with the same numbers, but the results are not the same because the first item found is used for checking.
(groupwithfuzz 1 '(500.1 499.9 500.5 499 125.03 125 300.01 300 450 455.02 455.7))
=> ((500.1 499.9 500.5) (499) (125.03 125) (300.01 300) (450) (455.02 455.7))

(groupwithfuzz 1 '(499.9 500.1 500.5 499 125.03 125 300.01 300 450 455.02 455.7))
=> ((499.9 500.1 500.5 499) (125.03 125) (300.01 300) (450) (455.02 455.7))
« Last Edit: June 25, 2024, 09:44:35 AM by dexus »

gile

  • Gator
  • Posts: 2522
  • Marseille, France
Re: Group list of numbers by fuzz value
« Reply #4 on: June 25, 2024, 11:23:41 AM »
Hi,
A slightly different way which uses a grouping by key and a rounding function.
Code - Auto/Visual Lisp: [Select]
  1. ;; gc:round
  2. ;; Rounds to nearest integer value
  3. ;;
  4. ;; Arguments
  5. ;; num : the number to be rounded
  6. (defun gc:round (num)
  7.   (if (minusp num)
  8.     (fix (- num 0.5))
  9.     (fix (+ num 0.5))
  10.   )
  11. )
  12.  
  13. ;; gc:roundTo
  14. ;; Round to nearest value based on prec
  15. ;;
  16. ;; Arguments
  17. ;; prec : the number specifying the rounding precision
  18. ;; num : the number to be rounded
  19. (defun gc:roundTo (prec num)
  20.   (if (zerop (setq prec (abs prec)))
  21.     num
  22.     (* prec (gc:round (/ num prec)))
  23.   )
  24. )
  25.  
  26. ;; gc:groupBy
  27. ;; Groups the items of a list according to the key generated by the specified function.
  28. ;; Returns a list of sub-lists whose first element is the key.
  29. ;;
  30. ;; Arguments
  31. ;; keySelector : the key generator function
  32. ;; lst : the list
  33. (defun gc:groupBy (keySelector lst / f key sub acc)
  34.   (setq f (eval keySelector))
  35.   (foreach x lst
  36.     (setq acc
  37.            (if (setq sub (assoc (setq key (f x)) acc))
  38.              (subst (cons key (cons x (cdr sub))) sub acc)
  39.              (cons (list key x) acc)
  40.            )
  41.     )
  42.   )
  43. )

Example (the first item in each sub-list is the generated key):
Code: [Select]
_$ (gc:groupBy '(lambda (x) (gc:roundTo fuzz x)) lst)
((455.7 455.7) (455.0 455.02) (450.0 450) (300.0 300 300.01) (125.0 125 125.03) (500.0 500.02 500))
To get the exact required list:
Code - Auto/Visual Lisp: [Select]
  1. (defun GroupWithFuzz (fuzz lst)
  2.     (mapcar
  3.       '(lambda (l) (reverse (cdr l)))
  4.       (gc:groupBy '(lambda (x) (gc:roundTo fuzz x)) lst)
  5.     )
  6.   )
  7. )

@dexus, this way is not affected by the order of the source list:
Code: [Select]
_$ (groupwithfuzz 1 '(500.1 499.9 500.5 499 125.03 125 300.01 300 450 455.02 455.7))
((500.1 499.9) (500.5) (499) (125.03 125) (300.01 300) (450) (455.02) (455.7))
_$ (groupwithfuzz 1 '(499.9 500.1 500.5 499 125.03 125 300.01 300 450 455.02 455.7))
((499.9 500.1) (500.5) (499) (125.03 125) (300.01 300) (450) (455.02) (455.7))
Speaking English as a French Frog

ribarm

  • Gator
  • Posts: 3327
  • Marko Ribar, architect
Re: Group list of numbers by fuzz value
« Reply #5 on: June 25, 2024, 11:51:05 AM »
@gile,
but I think this is single group :
Code: [Select]
(499.9 500.1) (500.5) (499)

and also this :
Code: [Select]
(455.02) (455.7)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

gile

  • Gator
  • Posts: 2522
  • Marseille, France
Re: Group list of numbers by fuzz value
« Reply #6 on: June 25, 2024, 12:48:24 PM »
@gile,
but I think this is single group :
Code: [Select]
(499.9 500.1) (500.5) (499)
The difference between 499 and 500.5 is 1.5, so, as @dexus noticed, the list order matters
- if 499 comes first in the list 500.5 won't be in the same group as (499 499.9 500.1)
- if 500.5 comes first in the list 499 won't be in the same group as (500.5 499.9 500.1)
- if 499.9 or 500.1 comes first in the list, all 4 will be in the same group (499.9 500.1 499 500.5)

I do not think @agnesika wanted such result depending on the list order and the liked topic in the first message is about grouping by key (which is what gc:groupBy does).
Speaking English as a French Frog

bruno_vdh

  • Newt
  • Posts: 110
Re: Group list of numbers by fuzz value
« Reply #7 on: June 26, 2024, 03:15:15 AM »
To get the exact required list:
Code - Auto/Visual Lisp: [Select]
  1. (defun GroupWithFuzz (fuzz lst)
  2.     (mapcar
  3.       '(lambda (l) (reverse (cdr l)))
  4.       (gc:groupBy '(lambda (x) (gc:roundTo fuzz x)) lst)
  5.     )
  6.   )
  7. )

Hi,
Why not?
Code - Auto/Visual Lisp: [Select]
  1. (defun GroupWithFuzz (fuzz lst)
  2.   (mapcar 'cdr (gc:groupBy '(lambda (x) (gc:roundTo fuzz x)) (reverse lst)))
  3. )

agnesika

  • Mosquito
  • Posts: 2
Re: Group list of numbers by fuzz value
« Reply #8 on: June 26, 2024, 03:40:02 AM »
Hi,
Here is a larger sample of parameter data:
Code - Auto/Visual Lisp: [Select]
  1. (setq *lst* '(360.243 378.578 388.578 479.098 488.516 489.098 500 506.926 507 511.829 519.16 520.502 520.917 521.829 522.216 616.657 620.048 624.996 626.657 629.326 720.487 899.991 899.994 899.996 900.002 900.005 900.005 900.005 999.999 1000.0 1000.0 1000.0 1000.01 1000.01 1000.01 2922.88 3109.41 3379.1 3400 3517.33 3521.58 3900 4000.0 4000 4000.0 4000.0 4000.0 5108.05 5183.91 5252.41 5258.41 5273.26 5273.32 5273.72 5294.62 5434.47 5438.9 5438.94 5444.94 5459.34 5459.84 5477.59 5609.36 5609.42 5630.26 5755.84 5811.98 5900.78 5919.05 5998.51 6157.25))
  2.  

I have tested both functions and noticed a small bug in gile's function:
Code: [Select]
_$ *lst*
(360.243 378.578 388.578 479.098 488.516 489.098 500 506.926 507 511.829 519.16 520.502 520.917 521.829 522.216 616.657 620.048 624.996 626.657 629.326 720.487 899.991 899.994 899.996 900.002 900.005 900.005 900.005 999.999 1000.0 1000.0 1000.0 1000.01 1000.01 1000.01 2922.88 3109.41 3379.1 3400 3517.33 3521.58 3900 4000.0 4000 4000.0 4000.0 4000.0 5108.05 5183.91 5252.41 5258.41 5273.26 5273.32 5273.72 5294.62 5434.47 5438.9 5438.94 5444.94 5459.34 5459.84 5477.59 5609.36 5609.42 5630.26 5755.84 5811.98 5900.78 5919.05 5998.51 6157.25)
_$ (GroupWithFuzz_wrap 1.5 *lst*) ; dgpuertas's
((360.243) (378.578) (388.578) (479.098) (488.516 489.098) (500) (506.926 507) (511.829) (519.16 520.502) (520.917 521.829 522.216) (616.657) (620.048) (624.996) (626.657) (629.326) (720.487) (899.991 899.994 899.996 900.002 900.005 900.005 900.005) (999.999 1000.0 1000.0 1000.0 1000.01 1000.01 1000.01) (2922.88) (3109.41) (3379.1) (3400) (3517.33) (3521.58) (3900) (4000.0 4000 4000.0 4000.0 4000.0) (5108.05) (5183.91) (5252.41) (5258.41) (5273.26 5273.32 5273.72) (5294.62) (5434.47) (5438.9 5438.94) (5444.94) (5459.34 5459.84) (5477.59) (5609.36 5609.42) (5630.26) (5755.84) (5811.98) (5900.78) (5919.05) (5998.51) (6157.25))
_$ (GroupWithFuzz_gile 1.5 *lst*)
((360.243) (378.578) (388.578) (479.098) (488.516 489.098) (500) (506.926 507) (511.829) (519.16) (520.502 520.917) (521.829 522.216) (616.657) (620.048) (624.996) (626.657) (629.326) (720.487) (899.991 899.994 899.996 900.002 900.005 900.005 900.005) (999.999 1000.0 1000.0 1000.0 1000.01 1000.01 1000.01) (2922.88) (3109.41) (3379.1) (3400) (3517.33) (3521.58) (3900) (4000.0 4000 4000.0 4000.0 4000.0) (5108.05) (5183.91) (5252.41) (5258.41) (5273.26 5273.32 5273.72) (5294.62) (5434.47) (5438.9 5438.94) (5444.94) (5459.34 5459.84) (5477.59) (5609.36 5609.42) (5630.26) (5755.84) (5811.98) (5900.78) (5919.05) (5998.51) (6157.25))

519.16 and 520.5 were not grouped together ( 1.34 difference, while the fuzz value is 1.5 )
@dgpuertas that LM:GroupByFunction is really nice.

I worked out my version with Chat GPT prompts, where the AI advised to initially sort the input data:
Code: [Select]
(defun _GroupWithFuzz (fuzz lst / qsort sorted_lst groups current_group current_val)

(defun qsort (lst)
(if (null lst)
nil
(append
(qsort (vl-remove-if-not '(lambda (x) (< x (car lst))) (cdr lst)))
(list (car lst))
(qsort (vl-remove-if-not '(lambda (x) (>= x (car lst))) (cdr lst))))
)
)


  ;; Sort the list
  (setq sorted_lst (qsort lst))
  ;; Initialize the groups list
  (setq groups '())
 
  ;; Process each element in the sorted list
  (while sorted_lst
    (setq current_val (car sorted_lst))
    (setq current_group (list current_val))
    (setq sorted_lst (cdr sorted_lst))
   
    ;; Group numbers within fuzz value
    (while (and sorted_lst (<= (abs (- (car sorted_lst) current_val)) fuzz))
      (setq current_group (cons (car sorted_lst) current_group))
      (setq current_val (car sorted_lst))
(setq sorted_lst (cdr sorted_lst))
)
   
    ;; Add the current group to the list of groups
(setq groups (cons (reverse current_group) groups)))
 
  ;; Return the list of groups
(reverse groups)
); defun _GroupWithFuzz

Code: [Select]
_$ (GroupWithFuzz_wrap 1.5 *lst*) ; dgpuertas's
((360.243) (378.578) (388.578) (479.098) (488.516 489.098) (500) (506.926 507) (511.829) (519.16 520.502) (520.917 521.829 522.216) (616.657) (620.048) (624.996) (626.657) (629.326) (720.487) (899.991 899.994 899.996 900.002 900.005 900.005 900.005) (999.999 1000.0 1000.0 1000.0 1000.01 1000.01 1000.01) (2922.88) (3109.41) (3379.1) (3400) (3517.33) (3521.58) (3900) (4000.0 4000 4000.0 4000.0 4000.0) (5108.05) (5183.91) (5252.41) (5258.41) (5273.26 5273.32 5273.72) (5294.62) (5434.47) (5438.9 5438.94) (5444.94) (5459.34 5459.84) (5477.59) (5609.36 5609.42) (5630.26) (5755.84) (5811.98) (5900.78) (5919.05) (5998.51) (6157.25))
_$ (_GroupWithFuzz 1.5 *lst*) ; mine
((360.243) (378.578) (388.578) (479.098) (488.516 489.098) (500) (506.926 507) (511.829) (519.16 520.502 520.917 521.829 522.216) (616.657) (620.048) (624.996) (626.657) (629.326) (720.487) (899.991 899.994 899.996 900.002 900.005 900.005 900.005) (999.999 1000.0 1000.0 1000.0 1000.01 1000.01 1000.01) (2922.88) (3109.41) (3379.1) (3400) (3517.33) (3521.58) (3900) (4000.0 4000 4000.0 4000.0 4000.0) (5108.05) (5183.91) (5252.41) (5258.41) (5273.26 5273.32 5273.72) (5294.62) (5434.47) (5438.9 5438.94) (5444.94) (5459.34 5459.84) (5477.59) (5609.36 5609.42) (5630.26) (5755.84) (5811.98) (5900.78) (5919.05) (5998.51) (6157.25))

dexus

  • Bull Frog
  • Posts: 232
Re: Group list of numbers by fuzz value
« Reply #9 on: June 26, 2024, 04:42:56 AM »
Lee mac write group - by function and i think is good for you purpose.

Code - Auto/Visual Lisp: [Select]
  1. (defun LM:GroupByFunction (lst fun / tmp1 tmp2 x1)
  2.   (if (setq x1 (car lst))
  3.     (progn
  4.       (foreach x2 (cdr lst)
  5.         (if (fun x1 x2)
  6.           (setq tmp1 (cons x2 tmp1))
  7.           (setq tmp2 (cons x2 tmp2))
  8.         )
  9.       )
  10.       (cons (cons x1 (reverse tmp1))
  11.             (LM:GroupByFunction (reverse tmp2) fun)
  12.       )
  13.     )
  14.   )
  15. )

You can use:
EDITED, Thanks Ribarm, i think its not necesary function, simple lambda
Code - Auto/Visual Lisp: [Select]
  1. (defun GroupWithFuzz (fuzz lst)
  2.   (LM:GroupByFunction lst (lambda (a b) (equal a b fuzz))  )
  3. )
  4.  

I don't know if it is any better, but below I changed LM:GroupByFunction to use a while loop instead of recursion:
Code - Auto/Visual Lisp: [Select]
  1. (defun LM:GroupByFunction (lst fun / x1 x2 tmp1 tmp2 rtn) ; Modded LM:groupByFunction to have a while loop instead of recursion
  2.   (while lst
  3.     (setq x1 (car lst))
  4.     (foreach x2 (cdr lst)
  5.       (if (fun x1 x2)
  6.         (setq tmp1 (cons x2 tmp1))
  7.         (setq tmp2 (cons x2 tmp2))
  8.       )
  9.     )
  10.     (setq rtn (cons (cons x1 (reverse tmp1)) rtn) ; save set in return var
  11.           lst tmp2 tmp1 nil tmp2 nil) ; reset lists
  12.   )
  13.   rtn
  14. )

Lee Mac

  • Seagull
  • Posts: 12939
  • London, England
Re: Group list of numbers by fuzz value
« Reply #10 on: June 26, 2024, 05:28:09 AM »
This may be marginally faster -
Code - Auto/Visual Lisp: [Select]
  1. (defun LM:groupequalfuzz ( lst fuz / rtn tmp x )
  2.     (while (setq x (car lst))
  3.         (setq lst (vl-remove-if '(lambda ( y ) (if (equal x y fuz) (setq tmp (cons y tmp)))) (cdr lst))
  4.               rtn (cons (cons x (reverse tmp)) rtn)
  5.               tmp nil
  6.         )
  7.     )
  8.     (reverse rtn)
  9. )

dgpuertas

  • Newt
  • Posts: 87
Re: Group list of numbers by fuzz value
« Reply #11 on: June 26, 2024, 08:46:28 AM »

@dgpuertas that LM:GroupByFunction is really nice.



Im agree, but Lee mac is really nice, not me.

I take this opportunity to thank Lee Mac for everything he does for the AutoLISP community. When he writes code, I read it carefully and always learn something. I am curious about his background because he has an in-depth knowledge of AutoCAD and (in my opinion) complex programming techniques. In AutoLISP, he is a global reference (along with some others who also contribute a lot).

ribarm

  • Gator
  • Posts: 3327
  • Marko Ribar, architect
Re: Group list of numbers by fuzz value
« Reply #12 on: June 27, 2024, 06:51:27 PM »
Here is my version... It should cover all attempts that depended on unsorted numbers... That's why pre sorting... Here is the result that is correct and I think that it's fastest one, if you don't include presorting which is neccessity...

Code - Auto/Visual Lisp: [Select]
  1. (defun groupnumsbyfuzz ( lst fuzz / _vl-sort-i x y r )
  2.  
  3.   (defun _vl-sort-i ( lst fun )
  4.     (mapcar (function (lambda ( x ) (nth x lst))) (vl-sort-i lst fun))
  5.   )
  6.  
  7.   (setq lst (_vl-sort-i lst (function <)))
  8.   (while (setq x (car lst))
  9.     (if (and (cadr lst) (<= (abs (- x (cadr lst))) fuzz))
  10.       (setq y (cons x y))
  11.       (if y
  12.         (setq r (cons (reverse (cons x y)) r) y nil)
  13.         (setq r (cons (list x) r))
  14.       )
  15.     )
  16.     (setq lst (cdr lst))
  17.   )
  18.   (reverse r)
  19. )
  20.  
  21. (setq *lst* (list 360.243 378.578 388.578 479.098 488.516 489.098 500 506.926 507 511.829 519.16 520.502 520.917 521.829 522.216 616.657 620.048 624.996 626.657 629.326 720.487 899.991 899.994 899.996 900.002 900.005 900.005 900.005 999.999 1000.0 1000.0 1000.0 1000.01 1000.01 1000.01 2922.88 3109.41 3379.1 3400 3517.33 3521.58 3900 4000.0 4000 4000.0 4000.0 4000.0 5108.05 5183.91 5252.41 5258.41 5273.26 5273.32 5273.72 5294.62 5434.47 5438.9 5438.94 5444.94 5459.34 5459.84 5477.59 5609.36 5609.42 5630.26 5755.84 5811.98 5900.78 5919.05 5998.51 6157.25))
  22.  
  23. (groupnumsbyfuzz *lst* 1.5)
  24. ((360.243) (378.578) (388.578) (479.098) (488.516 489.098) (500) (506.926 507) (511.829) (519.16 520.502 520.917 521.829 522.216) (616.657) (620.048) (624.996) (626.657) (629.326) (720.487) (899.991 899.994 899.996 900.002 900.005 900.005 900.005) (999.999 1000.0 1000.0 1000.0 1000.01 1000.01 1000.01) (2922.88) (3109.41) (3379.1) (3400) (3517.33) (3521.58) (3900) (4000.0 4000.0 4000.0 4000 4000.0) (5108.05) (5183.91) (5252.41) (5258.41) (5273.26 5273.32 5273.72) (5294.62) (5434.47) (5438.9 5438.94) (5444.94) (5459.34 5459.84) (5477.59) (5609.36 5609.42) (5630.26) (5755.84) (5811.98) (5900.78) (5919.05) (5998.51) (6157.25))
  25.  

M.R.
« Last Edit: June 28, 2024, 07:15:08 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

dgpuertas

  • Newt
  • Posts: 87
Re: Group list of numbers by fuzz value
« Reply #13 on: July 08, 2024, 12:10:46 PM »
Another chalenge near to this problem

group with fuzz but here between max and min value in each group.

for a list of xs values.

  .  .   .   .  .. .   . .              .  .   .  .            .             ..  . . .             .   .   .   .
  group 1              dx(fuzz) group 2         group 3       group 4            group 5     


in the sample distance of first element and last element un group 1 is more than fuzz (dx) but there are any values between them.


My contribution

Code: [Select]
(defun groupequalfuzzDistance ( lst fuz / rtn val x )
    (while lst
        (setq x (list (car lst))
      lst (vl-remove-if (function (lambda ( y ) (if (<= (- (car x) fuz) y (+ (last x) fuz)) (setq x (vl-sort (cons y x) (function <)))))) (cdr lst))
              rtn (cons x rtn)
             
        )
    )
    (setq rtn (vl-sort rtn (function (lambda (a b) (< (car a)(car b))))))
    (while rtn
       (setq x (car rtn)
     rtn (vl-remove-if (function (lambda (ls / xmn xmx)
   (setq xmn (- (car x) fuz)
xmx (+ (last x) fuz))
   (if (or (<= xmn (car ls) xmx) (<= xmn (last ls) xmx))
       (setq x (vl-sort (append x ls) (function <)))))) (cdr rtn))
     val (cons x val)
))      
   
(vl-sort val (function (lambda (a b) (< (car a)(car b)))))
)

« Last Edit: July 08, 2024, 12:28:25 PM by dgpuertas »

dgpuertas

  • Newt
  • Posts: 87
Re: Group list of numbers by fuzz value
« Reply #14 on: July 08, 2024, 12:22:28 PM »
another aproach:

xmn and xmx: val min and max calculated only when its necesary

Code: [Select]
(defun LM:groupequalfuzzDistance2 ( lst fuz / rtn val x xmn  xmx)
    (while lst
        (setq x (list (car lst))
      lst (vl-remove-if (function (lambda ( y ) (if (<= (- (car x) fuz) y (+ (last x) fuz)) (setq x (vl-sort (cons y x) (function <)))))) (cdr lst))
              rtn (cons x rtn)
             
        )
    )
    (setq rtn (vl-sort rtn (function (lambda (a b) (< (car a)(car b))))))
    (while rtn
       (setq x (car rtn)
     xmn (- (car x) fuz)
     xmx (+ (last x) fuz)
     rtn (vl-remove-if (function (lambda (ls)
   (if (or (<= xmn (car ls) xmx) (<= xmn (last ls) xmx))
       (setq x (vl-sort (append x ls) (function <))
     xmn (- (car x) fuz)
     xmx (+ (last x) fuz)
     )))) (cdr rtn))
     val (cons x val)
))
   
(vl-sort val (function (lambda (a b) (< (car a)(car b)))))
)


Samples
Code: [Select]
$ (setq llss (list 44.2745 8.61457 34.661 48.2132 40.4904 25.1886 44.6523 40.0429 13.1739 21.8857 8.77981 19.9027 2.39045 19.1862 16.5724 19.9981 18.2086 26.8078 47.2351 22.9914 27.324 49.507 31.0048 26.8124 19.0292 49.3747 19.9291 6.97839 13.8104 37.2818 12.6017 5.32968 40.3527 28.6324 39.8822 36.5882 19.2342 11.0787 31.1355 16.6442 4.09148 34.3555 43.0183 28.9776 43.5366 44.8909 45.3467 8.12053 39.6075 0.347162))
(44.2745 8.61457 34.661 48.2132 40.4904 25.1886 44.6523 40.0429 13.1739 21.8857 8.77981 19.9027 2.39045 19.1862 16.5724 19.9981 18.2086 26.8078 47.2351 22.9914 27.324 49.507 31.0048 26.8124 19.0292 49.3747 19.9291 6.97839 13.8104 37.2818 12.6017 5.32968 40.3527 28.6324 39.8822 36.5882 19.2342 11.0787 31.1355 16.6442 4.09148 34.3555 43.0183 28.9776 43.5366 44.8909 45.3467 8.12053 39.6075 0.347162)
_$ (LM:groupequalfuzzDistance llss 2.)
((0.347162) (2.39045 4.09148 5.32968 6.97839 8.12053 8.61457 8.77981) (11.0787 12.6017 13.1739 13.8104) (16.5724 16.6442 18.2086 19.0292 19.1862 19.2342 19.9027 19.9291 19.9981 21.8857 22.9914) (25.1886 26.8078 26.8124 27.324 28.6324 28.9776) (31.0048 31.1355) (34.3555 34.661 36.5882 37.2818) (39.6075 39.8822 40.0429 40.3527 40.4904) (43.0183 43.5366 44.2745 44.6523 44.8909 45.3467 47.2351 48.2132 49.3747 49.507))
_$


But i think that preorder list its easy and not necesary two loops..
« Last Edit: July 08, 2024, 12:32:25 PM by dgpuertas »