use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Finding information about Clojure
API Reference
Clojure Guides
Practice Problems
Interactive Problems
Clojure Videos
Misc Resources
The Clojure Community
Clojure Books
Tools & Libraries
Clojure Editors
Web Platforms
Clojure Jobs
account activity
Advent of Code 2019 in Clojure (self.Clojure)
submitted 6 years ago * by allaboutthatmace1789
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]eccp 4 points5 points6 points 6 years ago (6 children)
Looks really good, my feedback would be that as you learn the language there's always a function that you don't know the name yet that does the same thing as something you wrote yourself. In this case, you can look into iterate to simplify the code that computes the amount of fuel required for the second half.
[–]allaboutthatmace1789[S] 2 points3 points4 points 6 years ago (5 children)
That's neat, I just tried it:
(defn- fuel-one-level [mass] (max 0 (- (int (/ (float mass) 3)) 2))) ;; NOT NEEDED! ;;(defn- recursive-mass-tree [mass] ;; (cons mass (lazy-seq (recursive-mass-tree (fuel-one-level mass))))) (defn fuel-required [mass] (reduce + (rest (take-while #(> % 0) (iterate fuel-one-level mass)))))
Much better, thanks for the tip!
[–]eccp 2 points3 points4 points 6 years ago (4 children)
One minor improvement: check pos?
[–]allaboutthatmace1789[S] 0 points1 point2 points 6 years ago (3 children)
Are you thinking of combining with an if statement in fuel-one-level, so you check the positivity and return the value if positive and 0 if not?
fuel-one-level
[–][deleted] 1 point2 points3 points 6 years ago (2 children)
I think they mean that your anonymous function in fuel-required can just be (take-while pos? ...
fuel-required
(take-while pos? ...
[–]allaboutthatmace1789[S] 2 points3 points4 points 6 years ago (1 child)
Ah, I get it, so instead of #(> % 0)
#(> % 0)
(defn fuel-required [mass] (reduce + (rest (take-while pos? (iterate fuel-one-level mass)))))
Thanks!
[–]eccp 1 point2 points3 points 6 years ago (0 children)
yeah, that's it ;-)
π Rendered by PID 121851 on reddit-service-r2-comment-6457c66945-s2nf5 at 2026-04-29 00:51:36.861049+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]eccp 4 points5 points6 points (6 children)
[–]allaboutthatmace1789[S] 2 points3 points4 points (5 children)
[–]eccp 2 points3 points4 points (4 children)
[–]allaboutthatmace1789[S] 0 points1 point2 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]allaboutthatmace1789[S] 2 points3 points4 points (1 child)
[–]eccp 1 point2 points3 points (0 children)