Last year, I decided to solve an Advent of Code task in the most cursed way possible for a fun challenge. My choice as a programming language was LaTeX, which is in my opinion the most cursed Turing-complete language that has serious software written in it. Admittedly, as LaTeX is a pretty clunky and cumbersome language, so I chose to cheat a little and looked around to see if there were some more practical languages implemented in LaTeX (I personally think this makes the whole thing even more cursed). I settled on lisp-on-tex, which is a package implementing a Lisp dialect in LaTeX.
To keep things easy, I settled on Day one part
one. This was supposed to be a
tiny bit of fun, not some proper challenge. However, the problem was
not as trivial as it seemed, as the task pretty much requires some way
to convert digits represented as strings to integers, but there is
seemingly no way to do that in the stock version of
lisp-on-tex. However, adding the feature wasn’t too hard, and I added
a stringTOint
function to my version of
lisp-on-tex with just two
lines of code. (Edit 2024-12-17: My changes got merged into the upstream)
The way the solution is ran is by feeding the input into the pdflatex command compiling the LaTeX file, producing a PDF with the answer. The full source code of the solution can be found below:
\documentclass[a4paper]{article}
%% To run: append a line saying 'end' to the puzzle input
% run with pdflatex 01.tex < input, will output puzzle output in pdf file
\usepackage{lisp-on-tex}
\usepackage{expl3}
\expandafter\def\csname ver@l3regex.sty\endcsname{}
\usepackage{lisp-mod-l3regex}
\begin{document}
\lispinterp{
\defineM \sum :0)
(\define (\loop \i) (\begin
(\defineM \line '')
(\setB \line (\fgets))
(\lispif (\= \line 'end') \i (\begin
(\defineM \tok (\regExtract '[0-9]' \line))
(\defineM \l (\stringTOint (\concat (\nth \tok :0) (\nth \tok (\- (\length \tok) :1)))))
(\loop (\+ \i \l))))))
(\texprint (\loop :0))
(
}\end{document}