Last active
January 5, 2023 20:44
-
-
Save Vikasg7/fc3cbe491822da00f250aeb326deb366 to your computer and use it in GitHub Desktop.
double-cola kata in Clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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