Jump to content

Recommended Posts

same with fibonacci

(defun fibonacci* (n &key (offset 0) (every-x 1) (reverse nil))
  (let ((n (* n every-x)) (seq)) 
      (setf seq (find-everyother every-x (subseq (fibonacci 0 (+ n offset)) offset (+ n offset))))
      (if (equal reverse nil)
        seq
        (reverse seq))))


(fibonacci* 5 :offset 2)
=> (1 2 3 5 8)

(fibonacci* 5 :offset 5 :every-x 2)
=> (5 13 34 89 233)

(fibonacci* 5 :offset 5 :every-x 2 :reverse t)
=> (233 89 34 13 5)


;;;; in combination with "reading-list-by-steps"

(defun reading-list-by-steps (&key steps values (start (car values)))
  (let ((pos (car (position-item start values))))
    (append (list (nth pos values))
            (loop for i in steps
              do (setf pos (+ pos i))
              when (> pos (length values))
              do (setf pos (+ 0 i))
              collect (nth pos values)))))

(list-plot
 (reading-list-by-steps :steps '(1 -1 4 -3 2 -1 3 -2 4 1 1 -1)
                        :values (fibonacci* 14 :offset 6 :reverse t)
                        :start 89)
 :join-points t)
 

 

Edited by AM
added some stuff
Link to post
Share on other sites

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy