Skip to content

Instantly share code, notes, and snippets.

@atroche
Last active August 7, 2016 21:02
Show Gist options
  • Save atroche/5647270 to your computer and use it in GitHub Desktop.
Save atroche/5647270 to your computer and use it in GitHub Desktop.
Comparing different solutions to http://www.4clojure.com/problem/43
; my incredibly ugly solution
(fn rinter [s parts]
(letfn [(mod-index [s n] (keep-indexed (fn [index item] [(rem index n) item]) s))]
(map (fn [place]
(reduce (fn [acc [index v]]
(if (= index place)
(conj acc v)
acc))
[]
(mod-index s parts)))
(range parts))))
; daowen's elegant, idiomatic solution
#(apply map list (partition %2 %))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment