This repo contains my solutions for Advent of Code 2022 in two flavors: Java and Pascal.
These are my original Java solutions from December 2022, all wrapped into a NetBeans project. The typical way to run a certain puzzle is (from the project directory):
java -cp dist/AdventOfCode22.jar day01.Puzzle src/day01/input.txt
Replace the day number (01-25) as needed.
Note that input.txt contains the input data I received. Yours may (and most
probably will) be different. There will also be at least one example.txt file
per directory copy-pasted from the puzzle description.
In addition to the Java source all days contain a solution in Pascal for 8-bit CP/M, as I'm working on a simple Pascal compiler for Z80 in my spare time. There is a YouTube Playlist with videos of those solutions running on a ZX Spectrum Next. If you want to run them yourself and don't have real CP/M machine available, my recommended CP/M emulator is tnylpo.
Most Pascal solutions started out as straight ports of the Java ones after Advent of Code was already finished. Only some were done in December 2022 already and I did not necessarily do the rest "in order" (otherwise the big integer routines developed for day 21 would have seen more widespread use).
In many cases the CPU (28 MHz!) and memory (64 kB!) limitations of the target system forced me to rethink my approaches. A solution that would use several GB of memory was a clear no-go from the start. Regarding run-time, the rule-of-thumb I found was that a second in Java means a minute in tnylpo (both on my MacBook Air M1) and an hour on the ZX Spectrum Next (which, running at 28 MHz, is already quite fast compared to Z80 systems from the late 70s or early 80s that would often clock at 3.5 MHz).
So I had to optimize: Consider big-O, look for repetition patterns, use modulo arithmetic when numbers got too large, and in some cases even add some inline Z80 assembly. As a result, many Pascal solutions are actually much better (from an algorithmic perspective) than the original Java ones that "got me the stars".
That is, for me, probably the most interesting takeaway from doing this exercise on 8-bit: The limitations force you to create more efficient solutions, something that often gets lost in the age of GHz and GB machines.