Advent of Code 2022

This year I did Advent of Code again for the second year running. If you're not familiar with it, it is a set of daily language-agnostic code challenges during December. Here are some thoughts on my experience this year.

Community

The thing I love about Advent of Code is being able to discuss and compare approaches. At work we had a nice bunch of us doing it in various languages (including Excel!), and I was also on the LabVIEW AoC Discord. 

Progress

I didn't make it to the end or solve every puzzle, but I did make an attempt every day for 20 days, which I'm quite happy with. I shifted my daily routine around so I could try the puzzles before work, which meant I had a consistent chunk of time to dedicate to it. I won't keep this schedule change permanent though, as the reduced amount of sleep and exercise was getting to me towards the end! The 90 minutes that I could make time for wasn't always long enough for me to get a solution however, so most of the stars I missed are ones I struggled on. 

Favourite puzzle:

I liked the sand one (day 14) which was super satisfying to watch, and the not-Tetris one (day 17).

Strategies

After some trial and error, I found what works for me, which was:

  1. Always start by trying to follow the example on paper first before jumping into code. Often I didn't quite understand the problem by just reading it.
  2. Compare the puzzle input to the example input before starting as there might be a trick in there which isn't in the example. How big is it - will you have enough memory? Will the numbers require i64/u64? 
  3. If you get stuck, sometimes making a visualisation helps. Some 'clever' ways of representing the puzzle are more of a pain to debug and visualise.

Things I picked up, re-remembered or learnt:

  • I used Sets and Maps actually for the first time ever - I had spent the last few years in LV2016 so had never tried them before, but they definitely looked cleaner than having many arrays that had to be searched and indexed. 
  • The sign primitive! I had forgotten that one
  • If you need to calculate the max value of an array each iteration after appending 1 element to it, you can do 'max and min' of the old max and this element, rather than having to do 'array max and min'. 
  • Queues aren't only for messages, I always forget this
  • Map keys can be anything, including arrays
  • Arrays of clusters of arrays really do make life easier sometimes
  • Storing growing arrays of co-ords can be more efficient than storing growing 2d Boolean arrays
  • Clusters can make wiry messes easier to read, by 'naming' the wires when you unbundle
  • In-place element structures (e.g. for array/cluster access) also make code look really nice as well as providing performance benefits

Things I want to learn for next year:

  • A* algorithm - not one I learnt at school but I read that it is a better fit for where I was using breadth first searches.
  • Flood fill algorithm - I chickened out from implementing it this year.

Yep, both things that I want to learn are algorithms. I am actually quite lucky to be familiar with some of the algorithms needed to solve the puzzles despite not having studied CS, because at secondary school I studied 2 obscure maths modules in Decision Maths. It basically involved learning algorithms and then doing them from memory by hand on paper, which is a bit odd but you end up understanding them quite well when you aren't asking a computer to execute them for you. I'm really glad I took those modules, as they have been some of the most useful things I studied. I remember learning things like Dijkstra's algorithm, sorting algorithms, linear programming, critical path analysis, game theory, bin packing and all sorts of cool stuff. 


Anyway, that's all for 2022. Looking forward to a 2023 with lots of LabVIEW and community events. 

Comments