Hi folks. Long time no see/talk. Been sick, but not wishing to dwell on that. Hope everyone is well.
Anyway ... had need to write a simple average function that could take a list of numbers, or a list of coordinates, and average the result.
Thought it might make a fun simple challenge for the cumpulsive lisp authors that hang their hats here.
Given: (1 2 3 4 5) or ((1 2) (3 4) (5 6)) or ((1) (2 3) (4 5 6))
Return: 3.0 or (3.0 4.0) or (2.33333 2.66667 2.0) respectively.
(defun _Avg ( lst )
(cond
((vl-some 'vl-consp lst) (cons (_Avg (mapcar 'car lst)) (_Avg (mapcar 'cdr lst))))
((vl-some 'numberp lst) (/ (apply '+ (subst 0 nil lst)) (float (length lst))))
)
)
Cheers.