mardi 20 août 2013

The loop/recur constructs in clojure are really nasty, and not in a good way. Let's say it will force your brain to re-evaluate its knowledge on recursive processes.
 (fn [n]
      (loop [i 0
           a [1 1]]
      (cond (< n 3) a
            (= i (- n 2)) a
            :else (recur (inc i)
                         (conj a (apply + (drop i a))))))


Blame it on Sun's JVM.

ps: this is probably the ugliest guess-fested fibonacci function I've ever seen (and written). So far.

Aucun commentaire:

Enregistrer un commentaire