On Jul 13, 1:16 am, Christian Marks <9fv...@gmail.com> wrote: > Thank you. Based on this I've simplified the code further.
You could combine the test for a cycle leader with the cycle length count--but your original code, which calculates cycle lengths only if a cycle leader is identified, is more efficient! > (ns knuth > (:require [clojure.contrib.math :as math])) > > (defn random-perm [n] (shuffle (range n))) > (defn cycle-leader-length [perm i] (loop [cycle 1 j (nth perm i)] (cond (< j i) 1 (= j i) cycle :else (recur (inc cycle) (nth perm j))))) (defn order-perm [perm] (reduce (fn [order i] (math/lcm (cycle- leader-length perm i) order)) 1 perm)) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en