Skip to content

Instantly share code, notes, and snippets.

@corehello
Created March 15, 2017 05:03
Show Gist options
  • Save corehello/e1ac9875662313807299c493019d6ce3 to your computer and use it in GitHub Desktop.
Save corehello/e1ac9875662313807299c493019d6ce3 to your computer and use it in GitHub Desktop.
split number to odd list and even list which number is less than n but more than 0
(defun split-nums (n)
(if (>= n 0)
(if (= n 0)
'((0) NIL)
(if (oddp n)
(map 'list #'append `(NIL (,n)) (split-nums (- n 1)))
(map 'list #'append `((,n) NIL) (split-nums (- n 1)))))))
@corehello
Copy link
Author

CL-USER> (split-nums 9)
((8 6 4 2 0) (9 7 5 3 1))
CL-USER> (split-nums 13)
((12 10 8 6 4 2 0) (13 11 9 7 5 3 1))
CL-USER> (split-nums 17)
((16 14 12 10 8 6 4 2 0) (17 15 13 11 9 7 5 3 1))
CL-USER> (split-nums 1)
((0) (1))
CL-USER> (split-nums 10)
((10 8 6 4 2 0) (9 7 5 3 1))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment