Skip to content

Instantly share code, notes, and snippets.

@xavierRiley
Created December 14, 2012 12:52
Show Gist options
  • Select an option

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

Select an option

Save xavierRiley/4285276 to your computer and use it in GitHub Desktop.
Some ideas for the big scale exercise in Clojure
(defn remove-consecutive-duplicates [coll]
(let [shifted-coll (cons nil coll)]
(remove nil? (map (fn [x y] (if (not= x y) x)) coll shifted-coll))))
(remove-consecutive-duplicates
(seq
(filter even?
(take 32
(cycle
(concat
(range 0 10)
(rest (reverse (rest (range 0 10))))))))))
;; smush together 0123456789 with 87654321 then cycle
;; (0 2 4 6 8 6 4 2 0 2 4 6 8 6)
;;Infinite sequences are the tits
(take 32 (remove-consecutive-duplicates (filter even? (seq (cycle (concat (range 0 10) (rest (reverse (rest (range 0 10))))))))))
;; (0 2 4 6 8 6 4 2 0 2 4 6 8 6 4 2 0 2 4 6 8 6 4 2 0 2 4 6 8 6 4 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment