Skip to content

Instantly share code, notes, and snippets.

@Vikasg7
Last active January 5, 2023 20:44
Show Gist options
  • Save Vikasg7/fc3cbe491822da00f250aeb326deb366 to your computer and use it in GitHub Desktop.
Save Vikasg7/fc3cbe491822da00f250aeb326deb366 to your computer and use it in GitHub Desktop.
double-cola kata in Clojure
(ns cola.core)
(def names ["Sheldon" "Leonard" "Penny" "Rajesh" "Howard"])
(defn double-size [[size name]]
[(* 2 size) name])
(def group (map vector (repeat 1) names))
(def groups (lazy-cat group (map double-size groups)))
(defn who_is_next [[[size name] & res] n]
(cond (<= n size) name
:else (recur res (- n size))))
(println (= "Sheldon" (who_is_next groups 1))
(= "Sheldon" (who_is_next groups 6))
(= "Penny" (who_is_next groups 52))
(= "Leonard" (who_is_next groups 7230702951)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment