0 Members and 1 Guest are viewing this topic.
(setq lst '(1 12 16 21 26 32 40 42 56 66 74))
(parsel lst 24)
'((1 21) (21 42) (42 66) (66 74))
(<= (- 25 1) 24) -> T
(defun parsel (lst q / s ) ;i rl) (setq s (car lst)) (while (< s (last lst)) (setq i 0) (repeat (length lst) (if (> (+ s q) (- (nth i lst) s)) (setq i (1+ i)))) (setq rl (cons (list s (nth (1- i) lst)) rl) s (nth (1- i) lst))) (setq rl (cons (list s (last lst)) rl)) (prin1 (reverse rl)))
GreetingsUsing vanilla Autolisp :Given a sorted list of integers that always starts with 1Code: [Select](setq lst '(1 12 16 21 26 32 40 42 56 66 74))A function to parse the list with a maximum difference between values of a specified number of units ie 24Code: [Select](parsel lst 24)And return a list of lists with the start and end positions:Code: [Select]'((1 21) (21 42) (42 66) (66 74))(1 25) would be validCode: [Select] (<= (- 25 1) 24) -> TAny ideas ? Thanks -DavidPS I haven't figured out what to do if the difference is greater than 24 for 2 adjacent atoms.Here's where I'm at and it aint working !Code: [Select](defun parsel (lst q / s ) ;i rl) (setq s (car lst)) (while (< s (last lst)) (setq i 0) (repeat (length lst) (if (> (+ s q) (- (nth i lst) s)) (setq i (1+ i)))) (setq rl (cons (list s (nth (1- i) lst)) rl) s (nth (1- i) lst))) (setq rl (cons (list s (last lst)) rl)) (prin1 (reverse rl)))Any ideas ? Thanks -David
(defun parsel (lst q / s i rl) (setq s (car lst)) (while (< s (last lst)) (setq i 0) (repeat (length lst) (if (>= q (- (nth i lst) s));include equal to and adding s is not needed (setq i (1+ i)))) (if (not (zerop (- (nth (1- i) lst) s))) (setq rl (cons (list s (nth (1- i) lst)) rl) s (nth (1- i) lst)) (setq s (nth i lst)) )) ;(setq rl (cons (list s (last lst)) rl));Not sure why this is being done (reverse rl));Removed prin1, assuming it was placed for your testing
Not pretty but seems to work with your example
why not '((1 12) (12 16) (16 21) (21 26)..............)
A function to parse the list with a maximum difference between values of a specified number of units ie 24Code: [Select](parsel lst 24)
(setq lst '(1 12 16 21 26 32 40 42 56 66 74))(setq dif 2)
What should be the result of the function in this case?:Code: [Select](setq lst '(1 12 16 21 26 32 40 42 56 66 74))(setq dif 2)