Skip to content

Instantly share code, notes, and snippets.

@xavierRiley
Created August 10, 2012 13:05
Show Gist options
  • Select an option

  • Save xavierRiley/3314074 to your computer and use it in GitHub Desktop.

Select an option

Save xavierRiley/3314074 to your computer and use it in GitHub Desktop.
Clojure experiment
(defn get-dir [x]
(let [penul (first (rest (reverse x)))])
(let [final (last x)])
(when (>
(first (rest (reverse x)))
(last x)) (print "down"))
(when (>
(last x)
(first (rest (reverse x)))) (print "up"))
)
;(get-dir (seq (range 10)))
(defn saw-step [min max step dir]
(case dir
:up (cycle (concat (range min max step)
(range max min (- step))))
:down (cycle (concat (range max min (- step))
(range min max step)))
)
)
(defn rotate-while
"Rotates a collection left while (pred item) is true. Will return a
unrotated sequence if (pred item) is never true. Executes in O(n) time."
[pred coll]
(let [head (drop-while pred coll)]
(take (count coll) (concat head coll))))
(print (seq (take 12 (saw-step 5 16 1 :up))))
;; (rotate-while #(>= 7 %) (take 12 (saw-step 5 15 1 :up)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment