Code Your Way to Christmas: A Festive Challenge for Actuaries and Developers Alike

Join thousands of programmers worldwide in a holiday-themed coding challenge that goes beyond the basics. 

Advent of Code (AoC) is a freely-available coding challenge presented in the form of an advent calendar: on December 1st, we discover that our help is needed on a festive mission (for example, ensuring that Santa’s reindeer have enough magical energy to deliver all the presents). Each day until the 25th a new puzzle is released, and only upon successful completion of all puzzles is the savvy programmer able to save Christmas! 

With over 300,000 participants last year, AoC has gained popularity among software engineering and data science communities, but has received little attention from the actuarial profession. The challenge is language-agnostic, so can be attempted using any of the most popular languages applied in actuarial work including Python, R and even VBA/Excel.  

Realistic workflows 

Unlike books, where problems are generally well-posed from the beginning, AoC closely resembles ‘moving goal posts’ in a real workplace via a clever twist. Each day, the puzzle is split into two parts, with the second part only released to users once they have completed the first. This may be familiar to actuaries who have seen out-of-scope work added to a project. The two-part puzzle format encourages best practices in programming:  

  • using parameters, not hard-coding values (part two of the challenge may change assumptions!) 
  • building functions, not repeating code  
  • commenting code 
  • prioritising readability to aid future users (and yourself!) 
  • refactoring early and often 

 

Participants practice skills needed in actuarial work such as parsing input (and coping with unhelpful formats) and working with arrays, strings and regular expressions. 

Building the developer skillset 

AoC can help actuaries work on computer science and coding fundamentals, which are not always prominent in our training. This includes: 

  • Testing: AoC trains users to adopt a test-first workflow by providing a few test cases and an explanation of the intended output within the problem specification. Participants can use these to verify that their code is working correctly, before running it using their uniquely-generated and significantly larger individual input. While users are allowed as many attempts as needed to solve the puzzle, each failure is penalised by a time-out before a new attempt can be made. This discourages trial-and-error and rewards thorough testing.  

  • Version control: Most AoC participants use Git as an almost-automatic step in their coding workflow, then share their solutions via publicly-accessible repositories.  

  • Scaling and optimisation: Some puzzles may seem easy conceptually but run into practical difficulties when translated into a program. The obvious solution may take hours (days, years…) to run even on a powerful computer. Such situations encourage users to think beyond a ‘brute-force’ solution and consider efficient alternatives.   

    For example, this puzzle from 2021 asks users to simulate the growth of a population of lanternfish given conditions for aging (babies mature in two days) and reproduction (cloning every seven days). The problem states ‘you can model each fish as a single number that represents the number of days until it creates a new lanternfish’ then provides a vector showing the initial population in this format and demands the number of fish at a given future date. This specification naturally suggests a solution of amending and appending to the initial vector each day using the breeding logic. Unfortunately, the vector quickly expands, and the program becomes impossibly slow. The trick is to ignore the idea of modelling each fish, instead preferring to model the number of fish in each state on each day (reproduction in zero days, one day, two days, etc.) – this is much less computationally demanding.   

  • Data structures and algorithms: To the untrained eye, many puzzles appear intractable given the time constraints. Surprisingly, these problems can be simple for a computer scientist, whose toolbox includes well-known data structures and algorithms (for example, linked lists, and Dijkstra’s and A* algorithms). While such problems are intended to be solved using standard methods, it is often possible (with considerable effort) to complete them using only the basics, then learn from others’ solutions. In the workplace, a typical attitude is that ‘if the code runs, it’s good enough’ – AoC instead pushes coders to surpass ‘functional’ and strive for ‘efficient’.  

 

Feedback and community 

Although AoC puzzles remain available after publication, the best time to participate is December, when many people will be solving the same problems simultaneously. More importantly, users will share test cases, hints and even personalised advice.  

Doing small puzzles everyday creates the opportunity for repetition and reinforcement of learnings from earlier in the challenge, which is difficult to achieve in the workplace when actuaries may be working on longer projects or using others’ code. AoC is uniquely positioned to allow users to learn at their own pace while meeting the needs of both expert and inexperienced coders. 

Is AoC right for me? 

We encourage everyone to join in – at least on Day 1!  

Nevertheless, there are caveats: difficulty varies wildly, later puzzles demand a significant time commitment (>1hr/day), and some puzzles have little relevance to actuarial work. You will benefit most from AoC if you already have some experience with coding. 

Puzzles are arranged in approximate order of difficulty however, individuals will have different experiences based on their background. A new puzzle is released daily to all users regardless of their success on previous days. So, you could read all the puzzles and only attempt those which seem most appealing.  

AoC offers a leaderboard but we recommend solving purely for fun; leaderboards can create unhealthy competition, especially the global board which is dominated by experts in competitive programming. They can finish a puzzle within minutes using shortcuts and specialised libraries. This is an unreasonable goal for most users – instead, we recommend that the competitively-inclined actuary challenge themselves with additional tasks like using as many languages as possible or building visualisations of solutions.  

Whether you are looking for something fun and festive over the holidays or a challenging learning opportunity, put your technical skills to good use and help Santa save Christmas

CPD: Actuaries Institute Members can claim two CPD points for every hour of reading articles on Actuaries Digital.