mastodon.world is one of the many independent Mastodon servers you can use to participate in the fediverse.
Generic Mastodon server for anyone to use.

Server stats:

8.2K
active users

#adventofcode

0 posts0 participants0 posts today

Today I spent a LOT of time solving AoC2024 day2 puzzle.

I solved it in three ways:
1. Javascript, just how I normally write it (somewhat functional programming)
2. A fully FP javascript solution
3. clojure solution

I realized some interesting things:
1. the functional programming js solution was very pretty and clean, and I think js is pretty good at FP. (I'm just learning FP so maybe I'm wrong)

2. the effective LOC of both clojure and js solution were exactly the same, and I think in the cleanliness and readability department they are very similar. But maybe that is because I'm much more used to js

3. The effective LOC of the functional solutions were almost half the LOC of the "normal" solution

Here are the solutions
github.com/alirezaalavi87/adve

my solutions for solving advent-of-code puzzles. The solutions might be impemented in various languages. - alirezaalavi87/advent-of-code
GitHubadvent-of-code/2024/day2 at main · alirezaalavi87/advent-of-codemy solutions for solving advent-of-code puzzles. The solutions might be impemented in various languages. - alirezaalavi87/advent-of-code

I've finally got around to learning Python, and I'm currently working through some of the Advent Of Code '24 puzzles to get some hands on experience.

I appreciate some of what I think are Python's claims to fame. It's the first language in which I've worked with comprehensions. They're fun, but I'm not sure I see them as more than semi-arcane syntactic sugar for map() and filter(). Clearly, python's dynamic typing applied to list, tuple, comprehension, and generator is extremely powerful. Figuring out that I could just unpack all the elements from a short known-length list into a tuple has been handy.

The standard distro has modules for a great many things, and the package index has most everything else. On the other hand, how much is most? Maybe I'm missing something, but I can't find a module defining range_inclusive(start, stop) anywhere. Yes, I know it's trivial to write myself, but that seems at odds with Python's "batteries included" philosophy. All the research I've done seems to suggest the standard idiom is just to call range(start, stop + 1).

I love having access to a REPL again during code writing. It makes me miss the days of writing LISP in Emacs. I'm using PyCharm, which, of course, has the ability to load the current file directly into a new interpreter.

Probably my biggest gripe is that the language enforces so little and leaves so much to convention. Sure, it's higher-level than C, but it leaves you so many opportunities to shoot yourself in the foot at runtime. I had to laugh when reading up on classes, attributes, and scopes. Clearly, the moral was to define your data attributes inside the __init__ or you'll get some pretty bizarre bugs.