# 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 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 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 :-)

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×

• Lessons