Skip to content

Instantly share code, notes, and snippets.

@grafi-tt
Created November 21, 2013 09:45
Show Gist options
  • Select an option

  • Save grafi-tt/7578788 to your computer and use it in GitHub Desktop.

Select an option

Save grafi-tt/7578788 to your computer and use it in GitHub Desktop.
(define (fib-pathological n)
(define (go m prev tag acc)
(cond
((= m (+ n 1))
acc)
((< m 2)
(if (even? tag)
(go (+ m 1) m (quotient tag 2) (+ acc 1))
(go (+ m 2) m (quotient tag 2) (+ acc 1))))
((= prev (- m 2))
(if (even? tag)
(go (+ m 1) m (quotient tag 2) acc)
(go (+ m 2) m (quotient tag 2) acc)))
((= prev (- m 1))
(go (- m 2) m (+ (* tag 2) 1) acc))
(else
(go (- m 1) m (* tag 2) acc))))
(go n (+ n 1) 0 0))
(display (fib-pathological 20))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment