Skip to content
View in the app

A better way to browse. Learn more.

Learn more

pick-sample-from-center

Featured Replies

if you want to pick a sample from approx.center (depends on odd/even)  of a list... 

 

(defun pick-sample-from-center (list span)
  (let ((center (if (evenp (length list))
                  (/ (length list) 2)
                  (/ (1+ (length list)) 2)))
        (span (if (> span (length list))
                    (length list)
                    (append span))))
    (loop repeat span
      with startpoint = (if (evenp span)
                          (- center (/ span 2))
                          (- center (/ (1+ span) 2)))

      for i = startpoint then (incf startpoint)
      collect (nth i list))))


;;;EXAMPLES:

(pick-sample-from-center '(1 2 3 4 5 4 3 2 1) 7)
=> (2 3 4 5 4 3 2)

(pick-sample-from-center '(1 2 3 4 5 4 3 2 1) 3)
=> (4 5 4)

(pick-sample-from-center '(1 2 3 4 5 4 3 2 1) 6)
=> (3 4 5 4 3 2)

(pick-sample-from-center '(1 2 3 4 5 4 3 2 1) 20) ; (if (> span length) => input-list as output
=> (1 2 3 4 5 4 3 2 1)

 

Create an account or sign in to comment

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.