Compared to your "level 1", this is more like the question asked, since it asks for an algorithm rather than the answer. (I totally agree that it should be (+ number (* step iterations))).
In Clojure it's usually better to preference core functions, followed by reduce, followed by loop/recur.
I feel like you're right on the hierarchy of abstraction to use for Clojure functions (there's just so many, and many of them are composed)._
I could've just used pure-recursion without loop/recur but I don't get the power of the AST's tail-end optimizer for loops. Thank you for reminding me of the thread-macro.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Compared to your "level 1", this is more like the question asked, since it asks for an algorithm rather than the answer. (I totally agree that it should be
(+ number (* step iterations))
).In Clojure it's usually better to preference core functions, followed by
reduce
, followed byloop
/recur
.The clojure.core function approach is just:
But that's really using
iterate
to do the algorithm part. Soreduce
might be more in the spirit of things. It's shorter too 🙂Awesome breakdown! Thanks Paula. 🙏🏿
I feel like you're right on the hierarchy of abstraction to use for Clojure functions (there's just so many, and many of them are composed)._
I could've just used pure-recursion without
loop/recur
but I don't get the power of the AST's tail-end optimizer for loops. Thank you for reminding me of the thread-macro.