Jump to content
Sign in to follow this  
AM

shift-proportions

Recommended Posts

;;; CODE
            
(defun shift-proportions (integer-seq  shift &key (type 'primes))
  (let ((number-seq))
    (progn 
      (setf number-seq (cond ((equal type 'primes)
                              (primes 30))
                             ((equal type 'fibonacci)
                              (fibonacci 1 20))
                             ((equal type 'decimal)
                              (gen-integer-step 1 200 1))))
      (setf number-seq (append (reverse (neg! number-seq)) number-seq))
      (loop for i in integer-seq
        when (> i 0)
        collect (nth (+ (car (position-item i number-seq)) shift) number-seq)
        else collect (nth (- (car (position-item i number-seq)) shift) number-seq)))))


;;; EXAMPLE => the integer-seq must include only values from ":type"-system

(shift-proportions '(1 2 3 4 5 -3 2 -1 3 -8) 1 :type 'decimal)
=> (2 3 4 5 6 -4 3 -2 4 -9)
(shift-proportions '(1 2 -13 4 5 -3 2 -1 3 -8) 8 :type 'decimal)
=> (9 10 -21 12 13 -11 10 -9 11 -16)


(shift-proportions '(3 5 -17 -11 23) 1 :type 'primes)
=> (5 7 -19 -13 29)
(shift-proportions '(3 5 -17 -11 23) 5 :type 'primes)
=> (17 19 -37 -29 43)


(shift-proportions '(-5 55 -34 233 -89) 1 :type 'fibonacci)
=> (-8 89 -55 377 -144)
(shift-proportions '(-5 55 -34 233 -89) 3 :type 'fibonacci)
=> (-21 233 -144 987 -377)

 

Share this post


Link to post
Share on other sites

Your code contains some hard-wired boundaries (e.g., 30 for primes). Perhaps you want to make your boundaries dependant on your input in order to avoid that you could exceed them?

 

Best,

Torsten

Share this post


Link to post
Share on other sites

you are right, but it is okay for my use - if someone wants to make it smarter, it is very welcome - but I have to do some other things :-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×