Skip to content

Instantly share code, notes, and snippets.

@angusb
Created October 2, 2012 18:21
Show Gist options
  • Save angusb/3822022 to your computer and use it in GitHub Desktop.
Save angusb/3822022 to your computer and use it in GitHub Desktop.
ugly fib
(defn fib[x]
(loop [n 0 r ()]
(println n, r)
(cond (= x n) r
(or (= n 0) (= n 1)) (recur (inc n) (conj 1 r))
:else (recur (inc n) (conj (+ (last r) (butlast r)) r)))))
@lfranchi
Copy link

lfranchi commented Oct 2, 2012

(defn fib [x](reverse
%28loop [n 0 r %28%29]
%28cond %28= x n%29 r
%28or %28= n 0%29 %28= n 1%29%29 %28recur %28inc n%29 %28conj r 1%29%29
:else %28recur %28inc n%29 %28conj r %28+ %28first %28rest r%29%29 %28first r%29%29%29%29%29%29))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment