Trees reflected in a lake Joshua Reddekopp on Unsplash It seems like ages ago, but way back in November I committed to completing Advent of Code. I managed it all, and it was fun! All of my code is available on GitHub if you’re interested in seeing what I did, and I managed to get out a blog post for every one with a bit more commentary, which you can see in the series list above. Read more...
Today’s challenge, takes us back to a bit of computing history: a good old-fashioned Turing Machine. → Full code on GitHub !!! commentary Today’s challenge was a nice bit of nostalgia, taking me back to my university days learning about the theory of computing. Turing Machines are a classic bit of computing theory, and are provably able to compute any value that is possible to compute: a value is computable if and only if a Turing Machine can be written that computes it (though in practice anything non-trivial is mind-bendingly hard to write as a TM). Read more...
Today’s challenge, the penultimate, requires us to build a bridge capable of reaching across to the CPU, our final destination. → Full code on GitHub !!! commentary We have a finite number of components that fit together in a restricted way from which to build a bridge, and we have to work out both the strongest and the longest bridge we can build. The most obvious way to do this is to recursively build every possible bridge and select the best, but that’s an O(n! Read more...
Today’s challenge requires us to understand why a coprocessor is working so hard to perform an apparently simple calculation. → Full code on GitHub !!! commentary Today’s problem is based on an assembly-like language very similar to day 18, so I went back and adapted my code from that, which works well for the first part. I’ve also incorporated some advice from /r/haskell, and cleaned up all warnings shown by the -Wall compiler flag and the hlint tool. Read more...
Today’s challenge has us helping to clean up (or spread, I can’t really tell) an infection of the “sporifica” virus. → Full code on GitHub !!! commentary I thought I’d have another play with Rust, as its Haskell-like features resonate with me at the moment. I struggled quite a lot with the Rust concepts of ownership and borrowing, and this is a cleaned-up version of the code based on some good advice from the folks on /r/rust. Read more...
Today’s challenge asks us to assist an artist building fractal patterns from a rulebook. → Full code on GitHub !!! commentary Another fairly straightforward algorithm: the really tricky part was breaking the pattern up into chunks and rejoining it again. I could probably have done that more efficiently, and would have needed to if I had to go for a few more iterations and the grid grows with every iteration and gets big fast. Read more...
Today’s challenge finds us simulating the movements of particles in space. → Full code on GitHub !!! commentary Back to Python for this one, another relatively straightforward simulation, although it’s easier to calculate the answer to part 1 than to simulate. import fileinput as fi import numpy as np import re First we parse the input into 3 2D arrays: using numpy enables us to do efficient arithmetic across the whole set of particles in one go. Read more...
Today’s challenge asks us to help a network packet find its way. → Full code on GitHub !!! commentary Today’s challenge was fairly straightforward, following an ASCII art path, so I thought I’d give Rust another try. I’m a bit behind on the blog posts, so I’m presenting the code below without any further commentary. I’m not really convinced this is good idiomatic Rust, and it was interesting turning a set of strings into a 2D array of characters because there are both u8 (byte) and char types to deal with. Read more...
Today’s challenge introduces a type of simplified assembly language that includes instructions for message-passing. First we have to simulate a single program (after humorously misinterpreting the snd and rcv instructions as “sound” and “recover”), but then we have to simulate two concurrent processes and the message passing between them. → Full code on GitHub !!! commentary Well, I really learned a lot from this one! I wanted to get to grips with more complex stuff in Haskell and this challenge seemed like an excellent opportunity to figure out a) parsing with the parsec library and b) using the State monad to keep the state of the simulator. Read more...
In today’s challenge we deal with a monstrous whirlwind of a program, eating up CPU and memory in equal measure. → Full code on GitHub (and Python driver script) !!! commentary One of the things I wanted from AoC was an opportunity to try out some popular languages that I don’t currently know, including the memory-safe, strongly-typed compiled languages Go and Rust. Realistically though, I’m likely to continue doing most of my programming in Python, and use one of these other languages when it has better tools or I need the extra speed. Read more...