r/Clojure • • 2h 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.

5 Upvotes

6 comments sorted by

2

u/demosthenex 2h ago

Day one was 2 one-liners. Look at the standard frequencies function, sort and take.

2

u/LelouBil 2h ago

Oh thanks, I didn't even think to search for a built-in frequencies function !

2

u/1234pixel 1h ago

Some useful core functions as well as frequencies you might like to add to your toolkit of you've not seen them:

  • second (for sort-by)
  • take-last (for your inverse)
  • apply (an alternative for that reduce)

Sorry about the bad mobile formatting!

2

u/LelouBil 1h ago

Thanks, this is literally my first Clojure program, so It's everything I found online researching during the day.

2

u/camdez 1h ago

Here are just a few quick notes to get you started:

  1. Underscores are unconventional in Clojure identifiers. They may come up when interoping in some capacity (like destructuring JSON that is named that way), but no one uses them unless practically forced to. :)
  2. It's odd to immediately reach for 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.
  3. When writing a multiline function, put a newline after the argument list.
  4. It's fairly unusual to see the get function used. (get coll 0) is (first coll). (get coll 1) is (second coll). (get coll 42) is (nth coll 42).

1

u/LelouBil 1h ago

Thanks for the explanations !

I reached for defrecord because of Haskell x) Usually the first thing I did is to define a type to represent the input properly, and then a function to parse from the text to the type. Clojure seems to work more dynamically typed than I thought.

I noted your input about the other points. I didn't know about first second and nth, and I didn't think to look it up since I wanted to access map entries, but are you telling me they also work for maps ? Are maps and sequences the same under the hood ?