Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created August 23, 2011 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swannodette/1164447 to your computer and use it in GitHub Desktop.
Save swannodette/1164447 to your computer and use it in GitHub Desktop.
faster.clj
(set! *warn-on-reflection* true)
(set! *unchecked-math* true)
(defn shout [^java.util.ArrayList people ^long n ^long counter]
(cond
(= (.size people) 1) (.get people 0)
(zero? counter) (do
(.remove people 0)
(recur people n (inc counter)))
:else (let [counter (if (= counter (dec n))
0 (inc counter))
f (.get people 0)]
(.remove people 0)
(.add people f)
(recur people n counter))))
(defn josephus [people nth]
(let [al (java.util.ArrayList.)]
(dotimes [x people]
(.add al (inc x)))
(shout al nth 0)))
(defn run-el-recur-al []
(println (josephus 40 3))
(time
(dotimes [_ 1000000]
(josephus 40 3))))
(comment
(run-el-recur-al)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment