AM Posted September 27, 2016 Share Posted September 27, 2016 ;;;; function (-> don't know if this is already existing in opusmodus) (defun expand-intervals/integers (seq &key (type 'add) (value 1)) (cond ((equal type 'add) (loop for i in seq when (> i 0) collect (+ i value) when (< i 0) collect (- i value) when (= i 0) collect i)) ((equal type 'multiply) (loop for i in seq collect (* i value))) ((equal type 'expt) (loop for i in seq when (>= i 0) collect (expt i value) else collect (* (expt i value) -1))) ((equal type 'fibonacci) (loop for i in seq when (>= i 0) collect (+ i (fibonacci i)) else collect (- i (fibonacci (abs i))))))) ;;; examples (expand-intervals/integers '(0 -1 1 -2 2 -3 3) :type 'add :value 2) (expand-intervals/integers '(0 -1 1 -2 2 -3 3) :type 'multiply :value 2) (expand-intervals/integers '(0 -1 1 -2 2 -3 3) :type 'expt :value 2) (expand-intervals/integers '(0 -1 1 -2 2 -3 3 -4 4 -5 5) :type 'fibonacci) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.