Created
March 15, 2017 05:03
-
-
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
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 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))))))) |
Author
corehello
commented
Mar 15, 2017
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