Skip to content

Instantly share code, notes, and snippets.

@lispm
Created May 28, 2020 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lispm/d852a2b271b3e3175bc6433caeafcaf4 to your computer and use it in GitHub Desktop.
Save lispm/d852a2b271b3e3175bc6433caeafcaf4 to your computer and use it in GitHub Desktop.
; https://leetcode.com/problems/fair-candy-swap/
(defun candy-swap (a b &aux (sa (reduce #'+ a)) (sb (reduce #'+ b)))
(mapc (lambda (x &aux (y (+ x (/ (- sb sa) 2))))
(when (member y b)
(return-from candy-swap (values x y))))
a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment