/advent_of_code_2022

Solutions to the 2022 Advent of Code puzzles.

Primary LanguageNim

🎄 Advent of Code 2022 🎄

My solutions for the Advent of Code 2022 programming puzzles. Most of the first week's solutions were implemented in either Nim, Crystal or both, but after that I mostly stuck with Nim except for a few days where Picat came in handy (especially for its constraint solving abilities).

I've mostly used Haskell in the past and really like it, but some puzzles required dynamic programming which is easy in impure procedural languages, but more complicated in Haskell -- finding a mutation-free solution can be very difficult, and working with the ST monad added a lot of noise and cognitive load for me. I'm sure with more practice that gets easier.

One thing I found more awkward in Nim/Crystal is complex input parsing, which was usually easy and elegant thanks to Haskell's amazing Parsec, included in the standard library. After a couple of weeks of puzzling though, I learned to use Nim's strscans/scanf and strutils/tokenize functions which helped a lot. Picat seems a bit less polished from an input parsing point of view, so I mostly relied on split, although a few people mentioned to me that it has support for Prolog-style DCGs. I couldn't find much literature about how to use those properly in Picat, but I'll come back to them in future since I'll continue using Picat (and Nim) for at least the 2015 puzzles and maybe beyond.

Previous challenges

  • 2015 (working on these now in Picat)
  • 2019 (unfinished, will resume later...)
  • 2020 (mostly Haskell, one or two in Rust, Python and zz
  • 2021 (mostly Haskell, with one in the magical Picat

Current code stats with cloc

github.com/AlDanial/cloc v 1.90  T=0.12 s (1152.3 files/s, 302106.3 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
JSON                            16              0              0          28636
Nim                             55            781            470           3378
Markdown                        26            526              0            879
Crystal                         12             33              2            198
Python                           6             51             65            108
Bourne Shell                    11             38             14             77
Lua                              2             16             24             55
Ruby                             7              8             12             22
-------------------------------------------------------------------------------
SUM:                           135           1453            587          33353
-------------------------------------------------------------------------------

Retrospectives