DEV Community

loading...

Discussion on: Daily Challenge #271 - Simulate Population Growth

Collapse
rushsteve1 profile image
Steven vanZyl

Using an iterative style in Clojure. I think an iterative style is best suited for a sequential problem like this, and Clojure felt like a good fit.

(defn nb_year [p0 percent aug p]
  (count
    (take-while
      #(<= % p)
      (iterate
        #(Math/ceil (+ % (* % (/ percent 100)) aug))
        p0))))