Skip to content

Instantly share code, notes, and snippets.

@lumie1337
Created October 4, 2019 06:03
Show Gist options
  • Save lumie1337/3d7fb8a94b29884812488d3714210b28 to your computer and use it in GitHub Desktop.
Save lumie1337/3d7fb8a94b29884812488d3714210b28 to your computer and use it in GitHub Desktop.
(s/def ::phrases (s/map-of number? string?))
(def ^:private phrases {3 "Pling" 5 "Plang" 7 "Plong"})
(s/fdef raindrops
:args (s/cat :n number?)
:ret string?)
(defn raindrops
"Returns number as string unless it is divisible by 3, 5 or 7, in which case it returns
the concatenation of the words Pling (3), Plang (5) and Plong (7) for the divisible cases."
[n]
(as-> phrases $
(for [[d s] $ :when (= 0 (mod n d))] s)
(if (empty? $) (str n) (apply str $))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment