Advent of Code 2025 Day 1— Nim
Marketing Pitch and Impressions#
The Nim website describes the language like this:
Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula.
There are a few additional interesting points worth noting:
- Compiles to C, C++, or JavaScript, presumably making targeting new architectures easier.
- Automatic memory management via ARC or ORC, where ORC is ARC with cycles.
- Compile-time Function Execution (CTFE), which permits compile-time computation and AST manipulation.
- Syntax is similar to Python, using indentation for code blocks.
I quite like the ideas behind Nim. It has a decent library, automatic memory management, modern tooling and compiles to native code. The syntax is easy to read and pleasant to work with.
Unfortunately though, I can’t really see a compelling reason to use it over more mainstream languages. Perhaps the more compelling use cases would take advantage of Nim’s very strong metaprogramming features.
Visual Studio Code support for Nim is excellent.
The Code#
The code itself is straightforward and easy to read. Having the euclMod
function available in the base library is a nice touch. Also note the indexing
from the end of the string using ^ in positions(…).
The code itself is pretty straightforward. It generates a list of start and
unwrapped end positions for each move. For part 1 we just count the cases where
end mod 100 == 0. For part 2, we count the number of revolutions made, with
an additional adjustment for passing zero turning to the left.
| |
Install Nim and run#
The recommended way to install Nim is via choosenim, though most package
managers work as well. I used Homebrew.
# I installed via Homebrew
brew install nim
# Website recommends "choosenim"
curl https://nim-lang.org/choosenim/init.sh -sSf | sh
# Compile and run
nim r d01.nim