(defn- calculate-freebies [purchased-chocolates wrappers-per-freebie]
(loop [remaining-wrappers purchased-chocolates
free-chocolates 0]
(if (< remaining-wrappers wrappers-per-freebie)
free-chocolates
(let [new-chocolates (quot remaining-wrappers
wrappers-per-freebie)]
(recur
(+ (rem remaining-wrappers
wrappers-per-freebie)
new-chocolates)
(+ free-chocolates new-chocolates))))))
(defn calculate-chocos [bobs-money cost-of-chocolate wrappers-per-freebie]
(let [purchased-chocolates (quot bobs-money
cost-of-chocolate)
freebies (calculate-freebies purchased-chocolates
wrappers-per-freebie)]
(+ purchased-chocolates freebies)))
Note that I did go ahead and pull out calculate-freebies into a separate defn. I did that because a) it's a standalone concept and b) it makes calculate-chocos easier to read. If it weren't a standalone concept, I would have likely defined it in the let of calculate-chocos itself.