Skip to content

Instantly share code, notes, and snippets.

@commander-trashdin
Created September 11, 2020 17:22
Show Gist options
  • Save commander-trashdin/a00ca596ff3565973ebf733aaa99f2ab to your computer and use it in GitHub Desktop.
Save commander-trashdin/a00ca596ff3565973ebf733aaa99f2ab to your computer and use it in GitHub Desktop.
consecutive sum
(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