Created
September 11, 2020 17:22
-
-
Save commander-trashdin/a00ca596ff3565973ebf733aaa99f2ab to your computer and use it in GitHub Desktop.
consecutive sum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun consecsum (array) | |
| (loop :with res := (make-array 1 :adjustable t :fill-pointer 0) | |
| :with acc := (aref array 0) | |
| :for i :from 1 :below (length array) | |
| :for j := (- i 1) | |
| :if (= (aref array i) (aref array j)) | |
| :do (incf acc (aref array i)) | |
| :else | |
| :do (vector-push-extend acc res) | |
| (setf acc (aref array i)) | |
| :finally (unless (= 0 acc) (vector-push-extend acc res)) | |
| (return res))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment