r/Clojure • u/LelouBil • 3d ago
Looking for feedback on the first Advent of Code puzzle
Hi, this year I'm doing advent of code in Clojure, because the language looked interesting. I'm completely new to it, but I have done some Haskell before.
Here's my repo https://github.com/LelouBil/advent-of-code-2026
I am not sure if the code can be reduced/simplified further, or if the scaffolding in main (to run different days easily) could be improved.
11
Upvotes
5
u/camdez 3d ago
Here are just a few quick notes to get you started:
defrecord. You almost definitely shouldn't use it during AoC problems if you want to learn the Clojure way. Use a map, maaaaybe use a record later for something performance-sensitive.getfunction used.(get coll 0)is(first coll).(get coll 1)is(second coll).(get coll 42)is(nth coll 42).2
u/1234pixel 3d ago
Some useful core functions as well as
frequenciesyou might like to add to your toolkit of you've not seen them:second(forsort-by)take-last(for your inverse)apply(an alternative for that reduce)Sorry about the bad mobile formatting!
2
u/quotade 3d ago
This reminds me so much of myself six years ago when I started my Clojure journey--also with AoC (with 20yoe in Java back then). Like writing it as a executable application (instead of evaluating in the editor via a REPL), using "get" to access data in sequences/etc. (instead of first etc. or using the data structure as access function itself), writing functions for stuff the core namespace already has functions for (I for one used a lot of loop+recur before realizing most of that are simple filter/map/reduce operations).
Absolutely try to solve everything on your own, as good as you can, then take a look at a few of the other Clojure solutions and read the docs for all functions you haven't learned yet (I guess you already know https://clojuredocs.org ). You've already used for example map and reduce (where I wrote them as loops back in my first AoC season), so great job! You've already used for example map and reduce (where I wrote them as loops back in my first AoC season), so great job! Shows you're coming from Haskell.
Others already gave a couple of tips. What helped me most was when working with the REPL clicked. You writing a "main" program suggests you're not there yet. Read up on how to integrate the Clojure REPL in your editor. There should be plenty resources on the web. Apart from that and I'm repeating myself now, inspect other repos and learn from their approach in general and the functions they use in particular. (You can find them in the solution mega threads in the AoC subreddit and sometimes also in the Clojure subreddit.)
0
u/demosthenex 3d ago
Day one was 2 one-liners. Look at the standard frequencies function, sort and take.