(defun averageABCDs (stats) (let ((itteration 0) (temp) (count 0) (classes) (abcdSum) (result)) (progn (setf stats (sort stats '< :key #'(lambda (x) (car x)))) ; line to put data in order of itterations (dolist (x stats) (progn (if (not (= itteration (car x))) (progn (if (not (null abcdSum)) ; make sure something exists in abcdSum (setf result (append result (list(append `(,itteration) (mapcar #'(lambda (class values) (make-abcd :for class :a (floor (/ (first values) count)) :b (floor (/ (second values) count)) :c (floor (/ (third values) count)) :d (floor (/ (fourth values) count)))) classes abcdSum)))))) (setf itteration (car x)) (setf count 0) (setf abcdSum nil) (setf classes nil))) ; close if (dolist (abcds (cdr x)) (progn (if (null (setf temp (position (abcd-for abcds) classes))) (progn (setf classes (append classes (list(abcd-for abcds)))) (setf temp (- (length classes) 1)) (setf abcdSum (append abcdSum (list '(0 0 0 0)))))) ; close if (setf abcdSum (replace abcdSum (list (mapcar #'(lambda (x y) (+ x y)) (nth temp abcdSum) `(,(abcd-a abcds) ,(abcd-b abcds) ,(abcd-c abcds) ,(abcd-d abcds)))) :start1 temp)) )) ; close abcds loop (setf count (+ 1 count))));close stats loop (if (not (null abcdSum)) ; get the last values summed (setf result (append result (list(append `(,itteration) (mapcar #'(lambda (class values) (make-abcd :for class :a (floor (/ (first values) count)) :b (floor (/ (second values) count)) :c (floor (/ (third values) count)) :d (floor (/ (fourth values) count)))) classes abcdSum)))))) result)));close main