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.

Revisions

  1. xavierRiley revised this gist Sep 1, 2012. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions clojure_scales.clj
    Original file line number Diff line number Diff line change
    @@ -12,13 +12,13 @@

    ;(get-dir (seq (range 10)))

    (defn saw-step [min max step direction]
    (when (= direction :up)
    (cycle (concat (range min max step)
    (range max min (- step)))))
    (when (= direction :down)
    (cycle (concat (range max min (- step))
    (range min max step))))
    (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)))
    )
    )


  2. xavierRiley revised this gist Aug 13, 2012. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions clojure_scales.clj
    Original file line number Diff line number Diff line change
    @@ -12,21 +12,24 @@

    ;(get-dir (seq (range 10)))

    (defn saw-step [min max step]
    (cycle (concat (range min max step)
    (range max min (- step)))))
    (defn saw-step [min max step direction]
    (when (= direction :up)
    (cycle (concat (range min max step)
    (range max min (- step)))))
    (when (= direction :down)
    (cycle (concat (range max min (- step))
    (range min max step))))
    )

    ;; Inspiration - http://osdir.com/ml/clojure/2010-04/msg00722.html

    (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."
    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))))


    (get-dir (seq (take 12 (saw-step 5 15 1))))
    (print (seq (take 12 (saw-step 5 16 1 :up))))

    (rotate-while #(>= 7 %) (take 12 (saw-step 5 15 1)))
    ;; (rotate-while #(>= 7 %) (take 12 (saw-step 5 15 1 :up)))
  3. xavierRiley revised this gist Aug 13, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions clojure_scales.clj
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,7 @@
    (cycle (concat (range min max step)
    (range max min (- step)))))

    ;; Inspiration - http://osdir.com/ml/clojure/2010-04/msg00722.html

    (defn rotate-while
    "Rotates a collection left while (pred item) is true. Will return a
  4. xavierRiley revised this gist Aug 13, 2012. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion clojure_scales.clj
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,15 @@
    (range max min (- step)))))


    (get-dir (seq (take 12 (saw-step 5 15 1))))
    (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))))


    (get-dir (seq (take 12 (saw-step 5 15 1))))

    (rotate-while #(>= 7 %) (take 12 (saw-step 5 15 1)))
  5. xavierRiley created this gist Aug 10, 2012.
    20 changes: 20 additions & 0 deletions clojure_scales.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    (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]
    (cycle (concat (range min max step)
    (range max min (- step)))))


    (get-dir (seq (take 12 (saw-step 5 15 1))))