Another year comes to a close and brings with it the end of another excellent Advent of Code. Here at Optima, the spirit of competition remained high throughout; Roy kept up a close tail, but nobody was able to catch Jonners on his way to victory.
With that said, Jonners took the Optima trophy, along with the overall prize. In the sporting mood, he gave a portion of his winnings to Roy, who very kindly decided he’d like to donate them on to St Catherine’s Hospice. Optima decided to match this donation.
From the winner, Jonners Walton
When I first heard about the Advent of Code, I was excited, I’m a big fan of using programming for solving puzzles. As I wrote about in my most recent blog post on Quines, my introduction to APL came in the form of the puzzles Dyalog released in their annual Student Competition. Being quite new to APL (and programming in general) I didn’t expect to get too far, but it was such good fun that I ended up engrossed. I still haven’t finished all of the problems yet now that work has started again, but plan to revisit when I feel like a challenge, and perhaps see if I can re-write my existing solutions to be more robust and efficient.
The good
A number of the problems featured in this year’s challenges ended up being incredibly concise in APL, and I was always very pleased when I managed to keep my solution down to a single line (however, I did sometimes perform some formatting of the data prior to application). Since the problems got more complicated as the event progressed however, this happened less and less often.
The challenge on Day 5 was a good example, and you can read about some of the different approaches to tackling this one in a previous blog.
Day 6’s challenge involved determining which questions, in customs declaration each group had answered yes to, indicated by a letter in their form. Since the input could quickly be transformed into an array of character vectors, this problem seemed almost tailor made for APL, and both parts could be solved with only a few characters.
- Part 1: +/{+/⍵∊⍨⎕C ⎕A}¨d6
- Part 2: +/{+/∧⌿↑{⍵∊⍨(⎕C ⎕A)}¨' '(≠⊆⊢)⍵}¨d6
(where d6 is the transformed array of the puzzle input).
Day 18’s Part 1 was particularly easy in APL as the order of operation is already determined by position, instead of the BIDMAS convention. To get a working solution, all I did was reverse the string and execute! Some extra work had to go in to flipping each bracket since it would now point the wrong way, and to replace each ‘*’ with the APL primitive for multiplication ‘×’.
- +/{⍎('\*'⎕R'×')('o'⎕R'(')('\('⎕R')')('\)'⎕R'o')⌽⍵}¨d18
(where d18 is the puzzle input).
The Bad
While the problems often prompted clever and interesting ways of thinking about how a program should operate, and how data should be handled, one in my mind failed to do either of these, and was more of a chore than a challenge. Day 4’s passport checking was about as exciting as waiting in the passport queue at the airport in real life.
The Ugly
One in particular caused shudders throughout the community; Day 7’s deep dive into handbag recursion. 594 different coloured bags, which could each contain up to 4 different colours of bag! And some poor sod (in this case, you) at the airport luggage handling has to check that each bag contains the correct number of bags, and that each of those contains the correct number of bags, and that each of those contains the correct number of bags, and that each of those contains the correct number of bags, and that each of those contains the correct number of bags, and that each of those contains the correct number of bags...
My first instinct was to wrap the problem in a recursive dfn (which I still think would be the correct way to handle it) but after an entire evening banging my head against this problem, didn’t have the correct answer and couldn’t even tell if I was close. I ended up writing my solution as two separate trad_fns for easier debugging and tracing, and eventually got a correct answer to go with my headache. It wasn’t all ugly though, the problem did spawn some spectacular visualisations of the data from the community at r/adventofcode by users u/zopatista and u/illegalfield.
Afterword
I would like to say a huge thank you to James Heslip for rallying the troops around this event. As well as Sam Gutsell and Roy Salvi, I don’t think I would have gotten as far as I did without a few good friends to bounce ideas off and keep each other interested in each task. Further thanks to Eric Wastl, the organiser of the Advent of Code for spending the time to put these together each year. And last of all, thank you to Optima for the generous prize of £1,000,000 (which I am still waiting for the remaining £999,970 of, or maybe I misheard).
I look very forward to running something like this next year. I think these abstract little problems force our brains to think in a way which we are slightly less comfortable with in some circumstances. It leads to internal discussions like “ooh, how did you solve day seven?”, and a realisation of key areas and skills you feel you ought to improve on.
A huge thank you to the organisers and testers of Advent of Code (Eric Wastl, et al) and for everyone who took part.
APL Team Leader
James is an APL Programmer with a keen interest in mathematics. His love for computing was almost an accident. From a young age he always enjoyed using them- playing video games and such- but it was never considered that anything more would come from it. James originally had plans to pursue a career in finance. More about James.
Ask James about APL / APL Consultancy / APL Legacy System Support